public class Generic_test { |
public static void main(String[] args) { |
// 定义泛型类的一个String版本 |
Generic_demo<String> strObj = new Generic_demo<String>( "欢迎使用泛型类!" ); |
strObj.showDataType(); |
System.out.println(strObj.getData()); |
System.out.println( "----------------------------------" ); |
// 定义泛型类的一个Double版本 |
Generic_demo<Double> dObj = new Generic_demo<>( 3.1415 ); |
dObj.showDataType(); |
System.out.println(dObj.getData()); |
} |
} |