java泛型的问题
classGen<T>{privateTo;publicGen(Ta){this.o=a;}publicvoidshowTypeName(){System.out.pri...
class Gen<T>
{
private T o;
public Gen(T a)
{this.o=a;}
public void showTypeName()
{
System.out.println("类型是:"+o.getClass().getName());
}
}
Dog dog1=new Dog();
Dog dog2=new Dog();
Gen<Dog> gen1=new Gen<Dog>(dog1);
Gen gen2=new Gen(dog2);
gen1.showTypeName();
gen2.showTypeName();
两个都能输出数据类型,有什么区别?
Gen<Dog> gen1=new Gen<Dog>(dog1);
Gen gen2=new Gen(dog2);
这两有什么区别,第二个简单,为什么大家都用第一个。而且第二个系统会提示:
Multiple markers at this line
- Gen is a raw type. References to generic type Gen<T> should be
parameterized
- Type safety: The constructor Gen(Object) belongs to the raw type Gen.
References to generic type Gen<T> should be parameterized
- Line breakpoint:Demo2 [line: 21] - main(String[])
- Gen is a raw type. References to generic type Gen<T> should be
parameterized 展开
{
private T o;
public Gen(T a)
{this.o=a;}
public void showTypeName()
{
System.out.println("类型是:"+o.getClass().getName());
}
}
Dog dog1=new Dog();
Dog dog2=new Dog();
Gen<Dog> gen1=new Gen<Dog>(dog1);
Gen gen2=new Gen(dog2);
gen1.showTypeName();
gen2.showTypeName();
两个都能输出数据类型,有什么区别?
Gen<Dog> gen1=new Gen<Dog>(dog1);
Gen gen2=new Gen(dog2);
这两有什么区别,第二个简单,为什么大家都用第一个。而且第二个系统会提示:
Multiple markers at this line
- Gen is a raw type. References to generic type Gen<T> should be
parameterized
- Type safety: The constructor Gen(Object) belongs to the raw type Gen.
References to generic type Gen<T> should be parameterized
- Line breakpoint:Demo2 [line: 21] - main(String[])
- Gen is a raw type. References to generic type Gen<T> should be
parameterized 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询