开发者

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

开发者 https://www.devze.com 2023-01-11 10:40 出处:网络
P开发者_运维技巧roblem: Need to implement interface from 3rd party Java library in Scala ... Collection<?> getItemPropertyIds()

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

精彩评论

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