2017-03-08 92 views
0

轉換的Java到Scala代碼我面臨着一個奇怪的問題 一個例子可以在這裏https://gist.github.com/geoHeil/895260a04d3673b9848b345edf388a2d 發現該錯誤是將Java到Scala代碼

[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[_] = { 

當試圖轉換火花java的火花斯卡拉API 我努力將這個java類https://github.com/DataSystemsLab/GeoSpark/blob/master/src/main/java/org/datasyslab/geospark/showcase/UserSuppliedPolygonMapper.java#L59-L81移植到scala。

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 
    } 
} 

是說明該問題的最小樣品。

編輯

試圖修復我取代任何與其相應的類型的多邊形的一種可能的打字問題。 但這並不能幫助福克斯解決問題。

回答

1

你試過這個簽名嗎?

override def call(t: String): java.util.Iterator[Any] = { 
... 

因爲這個代碼示例成功編譯:

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] = { 
    Nil.iterator.asJava 
    } 
} 
+0

這部分是在正確的軌道上。現在的新問題是:'val result:collection.Seq [Polygon] with Growable [Polygon] = mutable.Buffer [Polygon]()'當作爲result.iterator調用時不會生成java.util.iterator,而是'類型不匹配; [error] found:迭代器[com.vividsolutions.jts.geom.Polygon] [錯誤] required:java.util.Iterator [com.vividsolutions.jts.geom.Polygon] ' –

+0

你可以使用'JavaConverters'作爲我做了? http://docs.scala-lang.org/overviews/collections/conversions-between-java-and-scala-collections.html – semsorock

+0

已經試過了。這是行不通的。 –