Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我是 Java 新手,有一点疑问。考虑这种情况:
我有 Fruit 类,这是超级类,还有两个子类,即 Apple 和 Orange。现在我想使用泛型概念将这两种类型的对象保存到一个列表对象中。
List<Fruit> fruits = new ArrayList<Fruit>(); fruits.add(new Apple()); fruits.add(new Orange());
但是要准备好fruits.get(0)返回Fruit对象并了解有关泛型的更多信息。
fruits.get(0)
Fruit