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)
精彩评论