class Foo { Foo getAnother(Foo foo) { switch (foo.runtimeType) { case Bar: return new Bar(); case Baz: return new Baz(); } return null; } }