标签:one nbsp list string set ring xtend setvalue ati
Java里面的泛型在实际开发中运用的很多,比如分页插件,List接口的实现类ArrayList。
public class ArrayList<E> extends AbstractList<E> implements List<E>
public static <T> void main(String[] args) {
List<T> mylist=new ArrayList<T>();
}
}
public class MyObject<T> extends BaseData { private T valueOne; private T valueTwo; public MyObject(T valueOne, T valueTwo) { this.valueOne = valueOne; this.valueTwo = valueTwo; } public T getValueOne() { return valueOne; } public void setValueOne(T valueOne) { this.valueOne = valueOne; } public T getValueTwo() { return valueTwo; } public void setValueTwo(T valueTwo) { this.valueTwo = valueTwo; } public static void main(String[] args) { MyObject<String> object = new MyObject<>("String one!", "String two"); System.out.println("value one " + object.valueOne + " value two " + object.valueTwo); } }
标签:one nbsp list string set ring xtend setvalue ati
原文地址:https://www.cnblogs.com/santiagohome/p/13373977.html