开发者

Convertion of Scala typed collection to Java with an unbounded wildcard, etc. Collection<?>

P开发者_运维技巧roblem: Need to implement interface from 3rd party Java library in Scala

...

Collection<?> getItemPropertyIds()

...

My solution is to use ...<here goes Iterable>.asInstanceOf[java.util.Collection[_]]

 val props:Map[Object,Property] = ...
 override def getItemPropertyIds()=props.keys.asInstanceOf[java.util.Collection[_]]

Is there better solution? Maybe with Predef's implicits?


Create some scala.Iterable, use scala.collection.asJavaCollection() (may be implicitly) to convert to java.util.Collection.


I try also this:

import scala.collection.JavaConversions
...
override def getItemPropertyIds() = JavaConversions.asCollection(props.keys)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜