How to use untyped Java util. List to scala 2.8 buffer
•
Java
I have to call some Java. Java that returns no type util. List. It seems that I can't convert it to scala 2.8 list without the compiler borking, and the following error occurs:
[INFO] found : java.util.List[?0] where type ?0 [INFO] required: java.util.List[AnyRef] [INFO] val modules: Buffer[AnyRef] = asScalaBuffer(FeedEntry.getModules)
I tried normal
import scala.collection.JavaConversions._ val modules: Buffer[AnyRef] = FeedEntry.getModules
As clear
val modules: Buffer[AnyRef] = asScalaBuffer(FeedEntry.getModules)
I know the type of item in the list. I've tried to set it to the type of buffer, but I always get the same error
I look around, but all documents assume that I want to enter a Java list How to convert an untyped list?
Solution
I think you just need to make it the right type
val modules: Buffer[AnyRef] = FeedEntry.getModules.asInstanceOf[java.util.List[AnyRef]]
Scala can get it from there and wrap it as a Scala collection by applying the implicit transformation of Java conversions
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码