学习泛型时遇到的一个问题 package test; public class Test { public static void main(String[] args) { BasicGeneric<B> bg = new BasicGeneric<B>(new B()); B b = bg.get(); BasicGeneric<int> bg2 = new BasicGeneric<int>(32); //此处有错 int b = bg2; System.out.println("b = " + b); BasicGeneric<String> bg3 = new BasicGeneric<String>("use generic");
} } class BasicGeneric<T> { private T a; public BasicGeneric(T a) { this.a = a; } public void set(T a) { this.a = a; } public T get() { return a; } } class B { B() { System.out.println("class B"); } } 代码注释处有无法通过编译的错误 而且盯了半小时 实在没看出来哪有问题 求指教