public class GenericA<T>
{
private GenericB<T> a;
public GenericB<T> getA()
{
return a;
}
public void setA(GenericB<T> a)
{
this.a = a;
}
public static void main(String[]args)
{
GenericA<Integer> test=new GenericA();
GenericB<Integer> b=new GenericB<Integer>();
b.setX(new Integer(-10));
test.setA(b);
System.out.println(test.a.getX());
}
}
class GenericB<T>
{
private T x;
public T getX()
{
return x;
}
public void setX(T x)
{
this.x = x;
}
}
泛型的嵌套
最新推荐文章于 2024-03-24 03:56:50 发布