如果我没记错的话,这段代码应该打印出来:
"dart.core.dynamic"
但打印以下内容:
"dynamic"
我的代码:
import 'dart:mirrors';
main() {
var mirror = reflectType(dynamic);
var symbol = mirror.qualifiedName;
print(symbol); // -> "dynamic"
}
如果我没记错的话,这段代码应该打印出来:
"dart.core.dynamic"
但打印以下内容:
"dynamic"
我的代码:
import 'dart:mirrors';
main() {
var mirror = reflectType(dynamic);
var symbol = mirror.qualifiedName;
print(symbol); // -> "dynamic"
}
I think "dynamic" is a perfectly good result.
The usual qualified name prefixes the type name with the declaring library's name. You are expecting it to prefix "dart.core", which is the name of the "dart:core" library, but "dynamic" is not declared in that library (https://api.dartlang.org/docs/channels/stable/latest/dart_core.html), so that would be the wrong prefix to use.
The "dynamic" type is a synthetic type that is not declared in any library - there is no "class" or "typedef" declaration that could declare a type behaving as "dynamic" does. It's only specified by the specification and implemented internally in the compilers and runtime systems.
Having a qualified name with no prefix makes perfect sense in this case. It's the same you get for "void".
这是答案如何在 Dart 中从 Type 实例中获取限定名称?
你忘记了
Symbol symbol = mirror.qualifiedName;
String qualifiedName = MirrorSystem.getName(symbol);