下面的JAVA代码出现泛型变量错误是什么原因啊 谢谢了
publicclassGenericFoo2<T1,T2>{privateT1foo1;privateT2foo2;publicvoidsetFoo1(T1foo1){t...
public class GenericFoo2<T1,T2>
{
private T1 foo1;
private T2 foo2;
public void setFoo1(T1 foo1)
{
this.foo1=foo1;
}
public void setFoo2(T2 foo2)
{
this.foo2=foo2;
}
public T1 getFoo1()
{
return foo1;
}
public T2 getFoo2()
{
return foo2;
}
}
class GenericFoo2Demo
{
public static void main(String[] args)
{
GenericFoo2<Integer,String> foo=new GenericFoo<Integer,String>();
foo.setFoo1(new Integer(1));
Integer i =foo.getFoo1();
System.out.println(i);
}
} 展开
{
private T1 foo1;
private T2 foo2;
public void setFoo1(T1 foo1)
{
this.foo1=foo1;
}
public void setFoo2(T2 foo2)
{
this.foo2=foo2;
}
public T1 getFoo1()
{
return foo1;
}
public T2 getFoo2()
{
return foo2;
}
}
class GenericFoo2Demo
{
public static void main(String[] args)
{
GenericFoo2<Integer,String> foo=new GenericFoo<Integer,String>();
foo.setFoo1(new Integer(1));
Integer i =foo.getFoo1();
System.out.println(i);
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询