//实例1
1//初识泛型
class Info<T>{ 2 private T name; 3 private T sex; 4 5 public void setName(T name){ 6 this.name=name; 7 } 8 public T getName(){ 9 return this.name; 10 } 11 12 public void setSex(T name){ 13 this.name=name; 14 } 15 public T getSex(){ 16 return this.sex; 17 } 18 } 19 20 public class Test{ 21 public static void main(args[] String){ 22 Info<String> info=new Info<String>(); 23 info.setName("Jack"); 24 info.setSex("man"); 25 System.out.println(info.getName()+" is a "+info.getSex()); 26 } 27 28 29 }