Reputation: 17724
Converting java to scala code I face a strange Problem An example can be found here https://gist.github.com/geoHeil/895260a04d3673b9848b345edf388a2d The error is
[error] src/main/scala/myOrg/CustomInputMapperWKT.scala:17: overriding method call in trait FlatMapFunction of type (x$1: String)java.util.Iterator[Any];
[error] method call has incompatible type
[error] override def call(line: String): Iterator[_] = {
When trying to convert spark java to spark scala API I am struggling to port this java class https://github.com/DataSystemsLab/GeoSpark/blob/master/src/main/java/org/datasyslab/geospark/showcase/UserSuppliedPolygonMapper.java#L59-L81 to scala.
Where
class CustomInputMapperWKT extends FlatMapFunction[String, Any] {
....
override def call(line: String): Iterator[_] = {
val result: collection.Seq[Polygon] with Growable[Polygon] = mutable.Buffer[Polygon]()
result.iterator
}
}
is the minimal sample describing the problem.
Trying to fix a possible typing problem I substituted Any with its respective type of polygon. But that doesn't help to Fox the problem.
Upvotes: 1
Views: 2321
Reputation: 564
Have you tried this signature?
override def call(t: String): java.util.Iterator[Any] = {
...
Because this code example is compiled successfully:
import org.apache.spark.api.java.function.FlatMapFunction
import collection.JavaConverters._
class CustomInputMapperWKT extends FlatMapFunction[String, Any] {
override def call(t: String): java.util.Iterator[Any] = {
...
result.iterator.asJava
}
}
Upvotes: 2