繁体   English   中英

飞镖:如何从课堂上获得“类型”

[英]Dart: how to get the “Type” from the class

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

基于http://www.dartlang.org/articles/m1-language-changes/#first-class-types ,例如类似以下的结构:

class Foo{}

Type type = Foo;

似乎可以通过分析仪,但在Dartium中运行时却给出错误。 这是VM尚不支持的,还是语法错误? 还是我需要以某种方式注释Foo,以便在运行时保留类型信息?

谢谢

理查德。

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

class Foo{}
var foo = Foo();

assert(foo.runtimeType == Foo);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM