Reputation: 1855
I'm getting the following error in Scala 2.11:
Error:(54, 85) type mismatch;
found : org.apache.pig.data.Tuple => Unit
required: java.util.function.Consumer[_ >: org.apache.pig.data.Tuple]
pigTest.getAlias("productData").forEachRemaining((x: org.apache.pig.data.Tuple) => print(x))
I'm confused because my function is a consumer so I don't know why it's being rejected or how to fix it.
Upvotes: 3
Views: 1946
Reputation: 1855
Scala 2.11 doesn't have good interoperability with Java 8 functions. The Pig code I'm calling is Java code that expects a Java consumer, so per this post I have to wrap the scala function.
Resulting code:
pigTest.getAlias("productData").forEachRemaining(toJavaConsumer((x: org.apache.pig.data.Tuple) => print(x)))
where:
def toJavaConsumer[T](consumer: (T) => Unit): Consumer[T] ={
new Consumer[T] {
override def accept(t: T): Unit = {
consumer(t)
}
}
}
Upvotes: 5