2. Java面向对象之泛型-构造方法中使用
package generic;
class Construtgeneric<T> {
private T value;
public Construtgeneric(T value) {
this.value = value;
}
public T getValue() {
return value;
}
public void setValue(T value) {
this.value = value;
}
}
public class GenericConstructDemo {
public static void main(String[] args) {
Construtgeneric<String> c = new Construtgeneric<String>("构造函数中使用泛型");
System.out.println(c.getValue());
}
}
class Construtgeneric<T> {
private T value;
public Construtgeneric(T value) {
this.value = value;
}
public T getValue() {
return value;
}
public void setValue(T value) {
this.value = value;
}
}
public class GenericConstructDemo {
public static void main(String[] args) {
Construtgeneric<String> c = new Construtgeneric<String>("构造函数中使用泛型");
System.out.println(c.getValue());
}
}
版权声明:本文为小平果原创文章,转载请注明:http://blog.csdn.net/i10630226