我有这个签名
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>>
答案 0 :(得分:1)
如果我理解你正在尝试做什么,这应该有效:
public final <T1 extends Pair<? extends Pair<? extends Enum<MyConstant>,
? extends BigDecimal>,
? extends Pair<? extends Enum<MyConstant>,
? extends BigDecimal>>>
void doSomething(final int number, final T1 pair);
我希望我能得到匹配的括号; - )