Reputation: 111
I'm having trouble iterating over a ImmutableList
from Guava in Scala. The only reason I'm working with them is because I'm working with code written in Java that uses the Guava API. However, the compiler doesn't seem to like it. Here's my code:
for (blockData: IBlockData <- block.P.a) {
*insert actions here*
}
The compiler errors with this:
Error:(24, 43) value filter is not a member of com.google.common.collect.ImmutableList[net.minecraft.server.v1_8_R3.IBlockData]
for (blockData: IBlockData <- block.P.a) {
^
Any help is greatly appreciated. Thanks!
Upvotes: 1
Views: 499
Reputation: 13959
To use Scala
s for
expression the object has to implement flatMap
and filter
which guava
collections do not. Scala
comes bundled with Java
converters, this should work:
import collection.JavaConverters._
for (blockData: IBlockData <- block.P.a.asScala) {
*insert actions here*
}
Upvotes: 3