クラス式があります:
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>
どうしたの?