泛化只能用于对象

/** * */ package test.fanxing; /** * @author 2172980000502 * */ public class GenDemo { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub // ----------------- test 1 -------------------- Gen<Integer> iOb; iOb = new Gen<Integer>(88); System.out.println(iOb.getOb()); System.out.println(iOb.getType()); // ----------------- test 2 -------------------- // Gen<int> iOb1;// It's wrong! T must be a object! // ----------------- test 3 -------------------- Gen<String> iOb2; iOb2 = new Gen<String>("hello"); System.out.println(iOb2.getOb()); System.out.println(iOb2.getType()); } }  

你可能感兴趣的:(object,String,Class)