André Rodrigues
André Rodrigues

Reputation: 11

Scala illegal Inheritance error doesn't make sense

I am writing a program in Java and Scala (using interop) and it keeps giving me this compile error wich doesn't make sense....

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

It says it inherits different types instances, but they are the same. They're both:

core.interfaces.IEvaluationFunction[core.representation.ILinearRepresentation[Double]]

Can somebody help me solving or understanding this?

The code:

This is where it gives error. The code is in Scala.

def createFermentationEvaluation(fermentationProcess:FermProcess,
     interpolationInterval:Int):FermentationEvaluation = {  
  return new FermentationEvaluation(fermentationProcess,interpolationInterval)
    with EvaluationFunctionAspect[ILinearRepresentation[Double]]
}

Here are the interface and classes that it uses:

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

I didn't include the body of any since it seems to be an inheritance problem.

Upvotes: 0

Views: 116

Answers (1)

Daniel C. Sobral
Daniel C. Sobral

Reputation: 297205

One of these types is java.lang.Double -- the one defined in Java, where there's no scala.Double, and the other is scala.Double -- the one defined in Scala.

These are two different types. scala.Double is really Java's primitive double, and when used as a type parameter it erases to Object. It cannot erase to java.lang.Double because that breaks when extending types under certain conditions.

Upvotes: 3

Related Questions