【发布时间】:2018-06-20 16:11:06
【问题描述】:
我收到错误 - 方法读取的类型不兼容;当我尝试使用 Scala 参数化类型覆盖 java 泛型函数名时。
这是我试图重写的 java 抽象函数。
public abstract class SRType{
//Other abstract functions
public abstract <T> T read()throws IOException;
}
我在 scala 中通过以下方式使用这个抽象类 -
abstract class SRType(val name: String) extends org.xyz.SRType {
// to convert to spark
val toSparkType: DataType
}
abstract class SRCollection(name: String, isTop: Boolean) extends SRType(name)
这是试图覆盖它的 scala 函数。
case class SRSTLString(override val name: String,
b: TBranch,
isTop: Boolean)
extends SRCollection(name, isTop) {
//Other functions
override def read[T]: String = {
//Code
}
}
错误代码-
[error] overriding method read in class SRType of type [T]()T;
[error] method read has incompatible type
[error] override def read[T]: String = {
任何建议将不胜感激。
【问题讨论】:
-
试试这个:覆盖 def read[String]: String = { // 代码 }
-
刚刚试了一下,还是一样的错误。
-
override def read[String](): String应该可以工作 -
不工作。它显示完全相同的错误。