//泛型方法,返回值T[] public static <T> T[] fun1(T...args){ return args; }
public static <T> void fun2(T[] arr){ for (int i = 0; i < arr.length; i++) { System.out.print(arr[i] + ".."); } }
//泛型接口 interface Infomation<T>{ void show(); }
//泛型类 class ImplInfo<T> implements Infomation<T>{
@Override public void show() { // TODO Auto-generated method stub System.out.println("just show"); }
public <T> void test(String context){ System.out.println(context); }
}
//泛型类 //<T extends Info2>,必须是info接口的子类 class Person<T extends Info2>{ private T info;
public T getInfo() { return info; }
public void setInfo(T info) { this.info = info; }
public Person(T info) { super(); this.info = info; } }
public class T6 { public static void main(String[] args) { //实例化Person对象,同时指定Introduction类型 Person<Introduction> person = new Person<Introduction>(new Introduction("dick", 123) );
//实例化Person对象,同时指定Contact类型 Person<Contact> person2 = new Person<Contact>(new Contact("北京大街", "575200")); } }