泛型方法
//泛型方法:<T> 返回值类型
public class MyGeneric {
public <T> T show(T t){
System.out.println("泛型方法:"+t);
return t;
}
}
public class Demo01 {
public static void main(String[] args) {
MyGeneric myGeneric = new MyGeneric();
//参数类型根据实际所写的参数类型所决定
myGeneric.show("张三");//泛型方法:张三
myGeneric.show(100);//泛型方法:100
myGeneric.show(3.14);//泛型方法:3.14
}
}
浙公网安备 33010602011771号