public class GenTest2{
public static void main(String[] args){
GenObj<String> gs = new GenObj<String>();
gs.setValue("zhangsan");
System.out.println(gs);
GenObj<Double> gv = new GenObj<Double>();
gv.setValue(120.0);
System.out.println(gv);
}
}
class GenObj<T>{
T value;
public T getValue(){
return value;
}
public void setValue(T v){
value = v;
}
public String toString(){
return "GenObj=[" + value + "]";
}
} |
|