我有一个类表达式:
public class Expression < E extends Number, V extends Number >
{
public Expression(E lV, OPERATION operation, V rV) {
}
public Expression(Expression< E, V > lE, OPERATION operation, Expression< E, V > rE) {
}
}
Expression.java 编译没有错误。
这是我的主要课程代码。
public static void main(String[] args)
{
// Line 1.
refactored.Expression< ?, ? > ex1 = new refactored.Expression< Double, Float >(10d, OPERATION.PLUS, 10f);
// Line 2.
refactored.Expression< ?, ? > ex2 = new refactored.Expression< Double, Float >(-3d, OPERATION.MUL, 1f);
// Line 3.
refactored.Expression< ?, ? > ex3 = new refactored.Expression< refactored.Expression< Double, Float >, refactored.Expression< Double, Float > >(ex1, OPERATION.MINUS, ex2);
}
第 3 行没有编译,它说:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The constructor Expression<Expression<Double,Float>,Expression<Double,Float>>(Expression<capture#1-of ?,capture#2-of ?>, OPERATION, Expression<capture#3-of ?,capture#4-of ?>) is undefined
Bound mismatch: The type Expression<Double,Float> is not a valid substitute for the bounded parameter <E extends Number> of the type Expression<E,V>
Bound mismatch: The type Expression<Double,Float> is not a valid substitute for the bounded parameter <V extends Number> of the type Expression<E,V>
它出什么问题了?