public class 类名<泛型表示符号> {
}
public interface 接口名<泛型表示符号> {
}
public <泛型表示符号> void setName(泛型表示符号 name){
}
public <泛型表示符号> 泛型表示符号 getName(泛型表示符号 name){
}
public class Test {
public static class IgenericImpl implements Igeneric<String> {
@Override
public String getName(String name) {
return name;
}
}
public static class MethodGeneric {
public <T> void setName(T name){
System.out.println(name);
}
public <T> T getName(T name){
return name;
}
}
public static void main(String[] args) {
MethodGeneric methodGeneric = new MethodGeneric();
methodGeneric.setName("oldlu");
methodGeneric.setName(123123);
MethodGeneric methodGeneric2 = new MethodGeneric();
String name = methodGeneric2.getName("Bjsxt");
Integer name1 = methodGeneric2.getName(123);
System.out.println(name);
System.out.println(name1);
/* IgenericImpl igeneric= new IgenericImpl();
String name = igeneric.getName("2023");
System.out.println(name);
Igeneric<String> igeneric1 = new IgenericImpl();
String name1 = igeneric1.getName("20231020");
System.out.println(name1);*/
/*Generic<String> generic = new Generic<>();
generic.setFlag("admin");
String flag = generic.getFlag();
System.out.println(flag);
Generic<Integer> generic1 = new Generic<>();
generic1.setFlag(100);
Integer flag1 = generic1.getFlag();
System.out.println(flag1);*/
}
}
interface Igeneric<T> {
T getName(T name);
}
class Generic<T> {
private T flag;
public void setFlag(T flag) {
this.flag = flag;
}
public T getFlag() {
return this.flag;
}
}