If I'm not wrong, this code should print:

 "dart.core.dynamic"

but following is printed:

 "dynamic"

My code:

    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".

其他提示

here is the answer How do I get the qualified name from a Type instance, in Dart?

you have forgotten about

 Symbol symbol = mirror.qualifiedName;
 String qualifiedName = MirrorSystem.getName(symbol);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top