我正在用 Java 和 Scala(使用互操作)编写一个程序,它一直给我这个没有意义的编译错误......
Description Resource Path Location Type illegal inheritance; inherits different type instances of trait IEvaluationFunction: core.interfaces.IEvaluationFunction[core.representation.ILinearRepresentation[Double]] and core.interfaces.IEvaluationFunction[core.representation.ILinearRepresentation[Double]] IConstructors.scala /ScalaMixins - Parjecoliv1/src/aop line 36 Scala Problem
它说它继承了不同类型的实例,但它们是相同的。他们都是:
core.interfaces.IEvaluationFunction[core.representation.ILinearRepresentation[Double]]
有人可以帮我解决或理解这个问题吗?
代码:
这就是出错的地方。代码采用 Scala 语言。
def createFermentationEvaluation(fermentationProcess:FermProcess,
interpolationInterval:Int):FermentationEvaluation = {
return new FermentationEvaluation(fermentationProcess,interpolationInterval)
with EvaluationFunctionAspect[ILinearRepresentation[Double]]
}
以下是它使用的接口(interface)和类:
public class FermentationEvaluation
extends EvaluationFunction<ILinearRepresentation<Double>>
trait EvaluationFunctionAspect[T <:IRepresentation]
extends IEvaluationFunction[T] {...}
public abstract class EvaluationFunction<T extends IRepresentation>
implements IEvaluationFunction<T>,java.io.Serializable {...}
public interface IRepresentation {...}
public interface ILinearRepresentation<E> extends IRepresentation {...}
我没有包含任何主体,因为它似乎是一个继承问题。
最佳答案
其中一种类型是 java.lang.Double
—— Java 中定义的类型,其中没有 scala.Double
,另一种是 scala .Double
——Scala 中定义的。
这是两种不同的类型。 scala.Double
实际上是 Java 的原始 double
,当用作类型参数时,它会删除为 Object
。它无法删除到 java.lang.Double
,因为在某些条件下扩展类型时会中断。
关于java - Scala非法继承错误没有意义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26644975/