class MyList<T> { private T t; public void setT(T t) { this.t = t; } public T getT() { return t; } }
class MyUtil { public <T> void showName(T t) { System.out.println("show_" + t); } public <T> void print(T t) { System.out.println("print_" + t); } }
//静态方法不能使用泛型类的泛型
interface Inter<T> { void show(T t); } //直接明确类型 class InterImpl implements Inter<String> { public void show(String t) { System.out.println(t); } }
//继续使用泛型
class InterImpl1<T> implements Inter<T> { public void show(T t) { System.out.println(t.getClass()); } }
class GenericSuper { public <T extends List> void getSize(T t) { System.out.println(t.size()); } public void getKeySet(HashMap t) { System.out.println(t.size()); } }
//TreeSet(Comparator<? super E> comparator)