根据有关'dart:mirror'
文件bool isSubtypeOf(TypeMirror other)
/**
* Checks the subtype relationship, denoted by [:<::] in the language
* specification. This is the type relationship used in [:is:] test checks.
*/
bool isSubtypeOf(TypeMirror other);
如果我正确理解文档,"bool isSubtypeOf(TypeMirror other)"
我认为它应该作为"operator is"
.
此代码按预期工作:
import "dart:mirrors";
void main() {
var objectMirror = reflectType(Object);
var result1 = objectMirror.isSubtypeOf(reflectType(bool));
var result2 = Object is bool;
print("Object is bool: $result1");
print("Object is bool: $result2");
}
输出:
Object is bool: false
Object is bool: false
但我无法理解“这个结果是否正确”?
import "dart:mirrors";
void main() {
var dynamicMirror = reflectType(dynamic);
var result1 = dynamicMirror.isSubtypeOf(reflectType(bool));
var result2 = dynamic is bool;
print("dynamic is bool: $result1");
print("dynamic is bool: $result2");
}
输出:
dynamic is bool: true
dynamic is bool: false