public class Test2 { /**
 * @param args
 */
public static void main(String[] args) {
// TODO Auto-generated method stub
Gencla ge=new Gencla();
Gencla ge1=new Gencla(10);
Gencla<String> ge2=new Gencla("hello");
Gencla<Integer> ge3=new Gencla(ge2);
System.out.println(ge.getCount()+" "+ge.getTper());
System.out.println(ge1.getCount()+" "+ge1.getTper());
System.out.println(ge2.getCount()+" "+ge2.getTper());
System.out.println(ge3.getCount()+" "+ge3.getTper());
}}
class Gencla<T>{
int count=-1;
T tper;
public Gencla(){
count=0;
}
public Gencla(int innum){
count=innum;
}
public Gencla(T nper){
this();
tper=nper;
}
public Gencla(Gencla<? extends T> ge){
this.count=ge.count;
this.tper=ge.tper;
}
T getTper(){
return tper;
}
int getCount(){
return count;
}
}
很明显,ge3实例化时用的应该是public Gencla(Gencla<? extends T> ge)这个构造方法,那个ge2就应该符合Gencla<? extends T>,在ge3中,T是Integer,那么,String就不应该属于<? extends Integer>?为什么能过编译和运行呢?