Java泛型中的通配符可以直接定义泛型类型的参数。而不用把该函数定义成泛型函数。
public class GenericsTest { public static void main(String[] args) { Listname = new ArrayList (); List age = new ArrayList (); List number = new ArrayList (); name.add("icon"); age.add(18); number.add(314); //getUperNumber(name);//1 getUperNumber(age);//2 getUperNumber(number);//3 } //通配符方式实现,很简洁 public static void getData(List data) { System.out.println("data :" + data.get(0)); } public static void getUperNumber(List data) { System.out.println("data :" + data.get(0)); } //普通方式实现
public staticvoid getData(List data) { System.out.println("data :" + data.get(0)); } public static void getUperNumber(List data) { System.out.println("data :" + data.get(0)); } }