This one is probably really stupid. How do you check the subclass of an object in Chapel?
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");
// ?, kinda Java-ish, what should I do?
if (type(a) == Apple.class()) {
writeln("Go away doctor!");
}
Though I'm asking about a subclass, I realize I don't know how to check if it's a Fruit
class either.
For an exact type match, you will want to write this:
To check if the type of
a
is a subtype ofFruit
, this will work:For reference, there's a list of functions that can similarly be used to check type information here
*Note that the parentheses in the
if
blocks are not necessary, so you could write this instead: