package code;
class Apple2{
T size;
public Apple2(){}
public Apple2(T size){
this.size = size;
}
public void setSize(T size){
this.size = size;
}
public T getSize(){
return this.size;
}
}
public class GenericTest3{
public static void main(String[] args) {
Apple2 a = new Apple2<>(6);
Integer as = a.getSize();
Apple2 b = a; //æ³åæ¦ç²ï¼å½æä¸ä¸ªå¸¦æ³åä¿¡æ¯çåéèµå¼ç»ä¸ä¸ªä¸å¸¦æ³åä¿¡æ¯çåéæ¶ï¼æ³åä¿¡æ¯ä¼è¢«æ¦é¤ï¼é»è®¤æ¯å£°æè¯¥æ³å形忶çä¸éç±»å
Number bs = b.getSize();
System.out.println(bs);
// Integer bs2 = b.getSize(); //æ¤æ¶ä¼æ¥éï¼æ³åä¿¡æ¯è¢«æ¦é¤ï¼å æ¤bsç±»ååºä¸ºNumber
Apple2 c = b; //æ³å转æ¢ï¼è¿ébå®é
ä¸å¼ç¨çè¿æ¯Apple2ç±»åï¼å æ¤è¿écä¹åºè¯¥æ¯Apple2ç±»å
Integer cs = c.getSize();
System.out.println(cs);
}
}