泛型
package Generics;
//泛型类 就是属性的数据类型不确定, 在创建对象的时候再确定.
public class a1<T> { //属性类型是<T>泛型
private T name;
public T getName() {
return name;
}
public void setName(T name) {
this.name = name;
}
}
//------------------------------
package Generics;
//必须是引用类型,比如:String, class类型, 基本类型要用包装类如Integer, Boolean...
public class a1Demo {
public static void main(String[] args) {
a1<String> a = new a1<String>();
a.setName("abc");
a1<Integer> i = new a1<Integer>();
i.setName(100);
a1<Boolean> b = new a1<Boolean>();
b.setName(true);
System.out.println(a.getName()+","+i.getName()+","+b.getName()+",");
}
}
标签:name,setName,getName,a1,泛型,public
From: https://www.cnblogs.com/lg369/p/17153803.html