groovy 泛型就是鸭子类型。T类似go语言中的interface,可以是任意类型
public class DictType{
private T localt;
}
class Example {
static void main(String[] args) {
// Creating a generic List collection
ListType<String> lststr = new ListType<>();
lststr.set("First String");
println(lststr.get());
ListType<Integer> lstint = new ListType<>();
lstint.set(1);
println(lstint.get());
}
}
public class ListType1<T>{
private T localt;
//返回泛型对象类型
public T get(){
return this.localt;
}
//给空对象赋值
public void set(T plocal){
this.localt = plocal;
}
}