发现thinking in java 4th edition的一个错误(二)

2014-11-24 08:59:17 · 作者: · 浏览: 4
on from Holder
99: // to Holder< extends Long>
100: // Unchecked method invocation:
101: // wildSubtype(Holder< extends T>,T) is
102: // applied to (Holder,Long)
103: Long r10 = wildSubtype(qualified, lng);
104: // OK, but can only return Object:
105: Object r11 = wildSubtype(unbounded, lng);
106: Long r12 = wildSubtype(bounded, lng);
107:
108: // wildSupertype(raw, lng); // Warnings:
109: // Unchecked conversion from Holder
110: // to Holder< super Long>
111: // Unchecked method invocation:
112: // wildSupertype(Holder< super T>,T)
113: // is applied to (Holder,Long)
114: wildSupertype(qualified, lng);
115: // wildSupertype(unbounded, lng); // Error:
116: // wildSupertype(Holder< super T>,T) cannot be
117: // applied to (Holder,Long)
118: // wildSupertype(bounded, lng); // Error:
119: // wildSupertype(Holder< super T>,T) cannot be
120: // applied to (Holder,Long)
121: }
122: } ///:~
看第104-105行:

// OK, but can only return Object:
Object r11 = wildSubtype(unbounded, lng);

Holder< >是不能传给Holder< extends T>的。