我有CardType1
and CardType2
that extendsCard
和 an Area
that has an ArrayList
of 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
?