public class TestShowGeneric {
public static void main(String[] args) {
TestShowGeneric a = new TestShowGeneric();
ShowGeneric b = new ShowGeneric();
b.setA("对ShowGeneric类中方法的调用");
a.fun(b);
}
public static void fun(ShowGeneric<? extends Number> c) {
System.out.println(c.getA());
}
}
class ShowGeneric<D> {
private D a;
public D getA() {
return a;
}
public void setA(D a) {
this.a = a;
}
}
在b.setA("对ShowGeneric类中方法的调用");a.fun(b);实参b为什么能够成功的传给public static void fun(ShowGeneric<? extends Number> c) 形参c; 作者: 车风波 时间: 2012-6-20 19:38
创建ShowGeneric对象b的时候没有定义泛型,所以fun()的形参ShowGeneric<? extends ArrayList>就没什么意义了,也就是你想传什么参数都行,只要是ShowGeneric对象作者: 龙秋地 时间: 2012-6-20 20:03
public class TestShowGeneric
{
public static void main(String[] args)
{
TestShowGeneric a = new TestShowGeneric();
ShowGeneric b = new ShowGeneric();
b.setA("对ShowGeneric类中方法的调用");
a.fun(b);
}
public static void fun(ShowGeneric<? extends Number> c)