このコードはダートVM(1.22.0-dev.9.0)上で動作しますが、DartPad(不明なバージョン)の作業を行いません。中Iterable <DeclarationMirror>をIterable <MethodMirror>にキャストできないのはなぜですか?
import 'dart:mirrors';
class Thing {
Thing();
}
void g(ClassMirror c) {
var constructors = c.declarations.values
.where((d) => d is MethodMirror && d.isConstructor) as Iterable<MethodMirror>;
print(constructors);
}
void main() {
g(reflectClass(Thing));
}
結果:
Unhandled exception:
type 'WhereIterable<DeclarationMirror>' is not a subtype of type 'Iterable<MethodMirror>' in type cast where
WhereIterable is from dart:_internal
DeclarationMirror is from dart:mirrors
Iterable is from dart:core
MethodMirror is from dart:mirrors
#0 Object._as (dart:core-patch/object_patch.dart:76)
#1 g (file:///google/src/cloud/srawlins/strong/google3/b.dart:9:55)
#2 main (file:///google/src/cloud/srawlins/strong/google3/b.dart:14:3)
#3 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:261)
#4 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:148)
(しかし、 。
0123:(MethodMirror on 'Thing')
で
DartPad結果)
注私はお互いを実装するいくつかのクラスをクラフトに手、そして同じことをすれば、それが動作することできれいに印刷さ
:(Instance of '_MM')
ソリューションのおかげで、バグのリンクを作成するためのオープン問題があり
のような新しいList<MethodMirror>
を作成することができます! –