java泛型可以派生子类实例吗?public class TestApple<T>
{
private T info; public TestApple(T info){
this.info=info;
} public void setInfo(T info){
this.info=info;
}
public T getInfo(){
return this.info;
} public static void main(String[] args)
{
TestApple<String> ta=new TestApple<String>("aaaaaaa");
System.out.println(ta.getInfo());
TestApple<Double> td=new TestApple<Double>(50.3);
System.out.println(td.getInfo());
}
}public class A5 extends TestApple<String>
{
public String getInfo(){
return "子类"+super.getInfo().toString();
}
public static void main(String[] args)
{
A5 a=new A5("dfgdf");
System.out.println(a.getInfo());
}
}
{
private T info; public TestApple(T info){
this.info=info;
} public void setInfo(T info){
this.info=info;
}
public T getInfo(){
return this.info;
} public static void main(String[] args)
{
TestApple<String> ta=new TestApple<String>("aaaaaaa");
System.out.println(ta.getInfo());
TestApple<Double> td=new TestApple<Double>(50.3);
System.out.println(td.getInfo());
}
}public class A5 extends TestApple<String>
{
public String getInfo(){
return "子类"+super.getInfo().toString();
}
public static void main(String[] args)
{
A5 a=new A5("dfgdf");
System.out.println(a.getInfo());
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货