如何用MyEclipse创建java泛型类(……高手请进)

2024-12-23 06:58:11
推荐回答(1个)
回答1:

public class Test {
private T name;
public T getName() {
return name;
}
public void setName(T name) {
this.name = name;
}
public static void main(String[] args) {
Test stringTest = new Test();
stringTest.setName("aaa");
System.out.println(stringTest.getName());
Test integerTest = new Test();
integerTest.setName(1111);
System.out.println(integerTest.getName());
}
}