public class MySpecificCollection<T> { private List<T> elements; public MySpecificCollection() { elements = new ArrayList<T>(); } public void add(T element) { elements.add(element); } public T get(int index) { return elements.get(index); } } MySpecificCollection<String> stringCollection = new MySpecificCollection<String>(); stringCollection.add("Hello"); stringCollection.add("World"); String firstElement = stringCollection.get(0); public class MySpecificCollection<T extends Number> { // ... }


上一篇:
下一篇:
切换中文