1.
2.
3.
4.
5.
(父类)
6.
(接口)
public class GenericFoo<T>
{
private T foo;
set{};get{};
}
GenericFoo<Boolean> foo1 = new GenericFoo<Boolean>();
GenericFoo<Integer> foo2 = new GenericFoo<Integer>();
2.
public class Generic<T1, T2>
{
private T1 foo1;
private T2 foo2;
set{};get{};
}
Generic<Integer, Boolean> foo = new Generic<Integer, Boolean>();
3.
public class Generic2<T>
{
private T[] fooArray;
set{};get{};
}
Generic2<String> foo = new Generic2<String>();
4.
public class ListGenericFoo<T extends List>
{
private T[] fooArray;
set{};get{};
}
ListGenericFoo<LinkedList> foo1 = new ListGenericFoo<LinkedList>();
ListGenericFoo<ArrayList> foo2 = new ListGenericFoo<ArrayList>();
5.
(父类)
public class Parent<T1, T2>
{
private T1 foo1;
private T2 foo2;
set{};get{};
}
(子类)
public class Child<T1, T2, T3> extends Parent<T1, T2>
{
private T3 foo3;
set{};get{};
}
6.
public class ChildClass<T1, T2> implements ParentInterface<T1, T2>
{
private T1 foo1;
private T2 foo2;
set{};get{};
}
(接口)
public interface ParentInterface<T1, T2>
{
public void setFoo1(T1 foo1);
public void setFoo2(T2 foo2);
public T1 getFoo1();
public T2 getFoo2();
}