public <泛型表示符号> void 方法名(泛型表示符号 形参名){
}
public <泛型表示符号> 泛型表示符号 方法名(泛型表示符号 形参名){
}
举例:
public class MethodGeneric {
// 无返回值类型
public <T> void setName(T name){
System.out.println(name);
}
// 有返回值类型
public <T> T getName(T name){
return name;
}
}
public class Test2 {
public static void main(String[] args) {
MethodGeneric method = new MethodGeneric();
method.setName("爱摸鱼的TT");
method.setName(1314);
MethodGeneric method1 = new MethodGeneric();
System.out.println(method1.getName("爱摸鱼的TT"));
System.out.println(method1.getName(1314));
}
}