以前の SO の質問に続いて、バスケットに収集したいのですがFruit
、途中でサブタイプを知りたいです。
class Banana : Fruit {
var color: string;
}
class Apple: Fruit {
var poison: bool;
}
class Fruit {
}
var a = new Apple(poison=true);
var b = new Banana(color="green");
if (a.type == Apple) {
writeln("Go away doctor!");
}
var basketDom = {1..1};
var basket: [basketDom] Fruit;
basket.push_back(a);
basket.push_back(b);
for b in basket {
writeln(b.type:string);
}
これにより、スーパータイプが出力されFruit
ます。どうすればこのバスケットから出入りApples
できますか?Bananas