package com.yuxi.demo.generics; public class MyGerneric <T> { private T foo; public T getFoo() { return foo; } public void setFoo(T foo) { this.foo = foo; } }
package com.yuxi.demo.generics;
public class TestGeneric <T,K>
{
private MyGerneric<K> myGerneric;
private T testFoo;
public static void main(String[] args)
{
TestGeneric<String, MyGerneric<String>> testGeneric = new TestGeneric<String, MyGerneric<String>>();
MyGerneric<MyGerneric<String>> myGernericOut = new MyGerneric<MyGerneric<String>> ();
MyGerneric<String> myGernericIn = new MyGerneric<String>();
myGernericIn.setFoo("I am dangerous");
myGernericOut.setFoo(myGernericIn);
testGeneric.setMyGerneric(myGernericOut);
System.out.println(testGeneric.getMyGerneric().getFoo().getFoo());
}
public MyGerneric<K> getMyGerneric()
{
return myGerneric;
}
public void setMyGerneric(MyGerneric<K> myGerneric)
{
this.myGerneric = myGerneric;
}
public void setTestFoo(T testFoo)
{
this.testFoo = testFoo;
}
public T getTestFoo()
{
return testFoo;
}
}