I\'m looking to write a function in a Dart superclass that takes different actions depending on which subclass is actually using it. Something like this:
You can use the runtimeType in switch :
class Foo {
Foo getAnother(Foo foo) {
switch (foo.runtimeType) {
case Bar:
return new Bar();
case Baz:
return new Baz();
}
return null;
}
}
In the case statements the class name is use directly (aka. class literal). This gives a Type object corresponding to the class mentionned. Thus foo.runtimeType can be compared with the specified type.
Note that you can not use generics for now in class literals. Thus case List<int>: is not allowed.