m*****k 发帖数: 731 | 1 class X< T extends List< ? extends Long> > {
public void someMethod(T t) {
t.add( new Long(0L)); // error
Number n = t.remove(0);
}
}
t.add( new Long(0L)); // error
弱弱地问这是为啥呢? |
l*********s 发帖数: 5409 | 2 Long is final, extends Long does not make senses. and the type erasure only
grantees that reading from T will be legit, the T could hold any thing
extends from Long, thus you run the risk of heterogeneity thus java
disallowed it. |
c*********e 发帖数: 16335 | 3 public final class Long
【在 m*****k 的大作中提到】 : class X< T extends List< ? extends Long> > { : public void someMethod(T t) { : t.add( new Long(0L)); // error : Number n = t.remove(0); : } : } : t.add( new Long(0L)); // error : 弱弱地问这是为啥呢?
|
o**2 发帖数: 168 | |
m*****k 发帖数: 731 | |
f*******n 发帖数: 12623 | 6 PECS - Producer Extends, Consumer Super
You cannot add anything to an "extends". You can only get things out of it.
You cannot get things out of a "super". You can only put things into it. |