我有这个签名
public final <T1 extends Pair<Pair<T3, T4>, Pair<T3, T4>>,
T3 extends Enum<MyConstant>,
T4 extends BigDecimal>
void doSomething(final int number, final T1 pair);
我可以这样使用
Pair<Pair<MyConstant, BigDecimal>, Pair<MyConstant, BigDecimal>> pair =
new Pair<Pair<MyConstant, BigDecimal>, Pair<MyConstant, BigDecimal>>(
new Pair<MyConstant, BigDecimal>(const1, value1),
new Pair<MyConstant, BigDecimal>(const2, value2));
_myObject.doSomething(1, pair);
我想要这个签名,但它不起作用:
public final <T1 extends Pair<T2, T2>,
T2 extends Pair<T3, T4>,
T3 extends Enum<MyConstant>,
T4 extends BigDecimal>
void doSomething(final int number, final T1 pair);
我收到此错误:
Bound mismatch: The generic method doSomething(int, T1) of type
MyObject is not applicable for the arguments (int,
Pair<Pair<MyConstant,BigDecimal>,Pair<MyConstant,BigDecimal>>). The
inferred type Pair<MyConstant,BigDecimal> is not a valid substitute
for the bounded parameter <T2 extends Pair<T3,T4>>