泛型方法

//泛型方法:<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

}
}

posted @ 2023-02-20 10:41  惊鸿宴远赴人间  阅读(12)  评论(0)    收藏  举报