2

如何获取给定类的“类型”实例?

基于http://www.dartlang.org/articles/m1-language-changes/#first-class-types,例如如下构造:

class Foo{}

Type type = Foo;

似乎可以通过分析器,但在 Dartium 中运行时会出错。这只是 VM 中尚不支持,还是语法错误?或者我是否需要以某种方式注释 Foo ,以便在运行时保留类型信息,或者其他什么?

谢谢

理查德。

4

2 回答 2

1

基于https://groups.google.com/a/dartlang.org/forum/#!msg/misc/P3XdXeoZ4CY/9IBwkV-CTy0J我猜这个功能还没有在 dart vm 中!

于 2012-11-19T17:46:27.617 回答
1

现在您可以使用https://api.dartlang.org/stable/2.3.1/dart-core/Object/runtimeType.html

class Foo{}
var foo = Foo();

assert(foo.runtimeType == Foo);
于 2019-06-03T20:26:33.647 回答