4

変数に格納された Type のインスタンスを使用して、Dart でオブジェクトの型をテストすることは可能ですか? 例えば

Foo foo = new Foo();

Type testtype = Foo;

if (foo is testtype) {
  print("foo matched testype");
}

これにより、次の警告が表示されます。

The name 'testtype' is not a type and cannot be used in an 'is' expression

これを行う方法はありますか?

最終的には、 Type をパラメーターとして関数に渡し、これを使用して「is」型テストを実行したいと考えています。

4

2 に答える 2

1
Foo foo = new Foo();

Type testtype = Foo;

if (foo.runtimeType == testtype) {
  print("foo matched testype");
}
于 2013-10-09T15:30:34.247 に答える
0

If (foo.runtimeType == testtype.runtimeType)

于 2013-10-09T14:39:24.247 に答える