我试图模拟hadoop公共api java库中的filestatus类。导致以下编译器错误:
Error:(34, 24) double definition:
override def compareTo(o: Any): Int at line 34 and
override def compareTo(x$1: T): Int at line 34
have same type after erasure: (o: Object)Int
val mockFile = mock[FileStatus]
Error:(34, 24) name clash between defined and inherited member:
def compareTo(x$1: T): Int in trait Comparable and
override def compareTo(o: Any): Int at line 34
have same type after erasure: (x$1: Object)Int
val mockFile = mock[FileStatus]
问题可能在于这个类扩展了 Comparable
不指定任何类型参数。源代码中的相关java代码片段可以在这里看到:
public class FileStatus implements Writable, Comparable {
// <snipped>
@Override
public int compareTo(Object o) {
FileStatus other = (FileStatus)o;
return this.getPath().compareTo(other.getPath());
}
// <snipped>
}
要重现编译器错误,只需在org.apache上添加一个依赖项。hadoop:hadoop-common:2.6.5,并创建以下scalatest方法:
test("my failing test") {
// your imports
import org.apache.hadoop.fs.FileStatus
// code that fails
val mockFile = mock[FileStatus]
}
有没有办法解决这个问题,让这个类通过scalamock被模仿?这是Scalamock3.6.0、Scala2.11和OracleJDK1.8.0\u181的参考资料。
暂无答案!
目前还没有任何答案,快来回答吧!