我有CardType1and CardType2that extendsCard和 an Areathat has an ArrayListof Card。这个数组将充满CardType1和CardType2对象,但我最终需要像这样访问它们:
for (CardType1 card : this.cards) { ...
概述:
public class Area {
List<Card> cards = new ArrayList<Card>();
..
}
public class Card {..}
public class CardType1 extends Card {..}
public class CardType2 extends Card {..}
如何仅迭代列表中的一个子类型List<Card> cards?