这有效
class Deck {
var cards : Stack[Card] = new Stack[Card]
for (card <- Card.possibleCards.keySet; suit <- Card.suits) {
cards.push(new Card(card, suit))
}
}
但这不是
class Deck[Card] extends Stack[Card] {
for (card <- Card.possibleCards.keySet; suit <- Card.suits) {
push(new Card(card, suit))
}
}
我收到此错误:
error: class type required but Card found
有人可以告诉我为什么吗?
答案 0 :(得分:0)
这只是一个语法错误,我需要从Deck中删除类声明卡。 像这样
class Deck extends Stack[Card] {
for (card <- Card.possibleCards.keySet; suit <- Card.suits) {
push(new Card(card, suit))
}
}