yuxishua

博客园 首页 联系 订阅 管理
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;
	}

}

 

posted on 2015-12-15 14:02  yuxishua  阅读(171)  评论(0编辑  收藏  举报