when I compile following code it failure and throw error:
MainTest.scala:11: error: missing argument list for method read in object MainTest
object GenericTest {
def createStream[T: ClassTag](endpoint: String, shardId: Int, func: RecordEntry => T): DStream[T] = {
null
}
def createStream[T: ClassTag](endpoint: String,func: RecordEntry => T): DStream[T] = {
null
}
}
object MainTest {
def main(args: Array[String]): Unit = {
val ddd = GenericTest.createStream[String]("6", 1, read)
}
def read(record: RecordEntry): String = {
s"${record.getString(0)},${record.getString(1)}"
}
}
If I remove the second method createStream in GenericTest, then MainTest can compile successfully. Or If I modify the MainTest as following(remove the "[String]" when call GenericTest.createStrem(xxx), it can compile successfully.
def main(args: Array[String]): Unit = {
//remove the "[String]"
val ddd = GenericTest.createStream("6", 1, read)
}
Or if I modify the MainTest as following(add the red convert to func) it can compile successfully.
def main(args: Array[String]): Unit = {
// add the " _" after read parameter
val ddd = GenericTest.createStream[String]("6", 1, read _)
}
Any idea about this issue, why it compile failure ? And what's the correct way should be like ?