1
我想沒有任何成功找到了泛型類型的Iterable
類(如Set<myGenericType>
或List<myOtherGenericType>
)的泛型類型可迭代的(設置
例如:
如果instanceMirror.getField(myField).reflectee
是Set<Toto>
那我也沒有辦法通過自省來檢索類型Toto
。
謝謝你的幫助!
我想沒有任何成功找到了泛型類型的Iterable
類(如Set<myGenericType>
或List<myOtherGenericType>
)的泛型類型可迭代的(設置
例如:
如果instanceMirror.getField(myField).reflectee
是Set<Toto>
那我也沒有辦法通過自省來檢索類型Toto
。
謝謝你的幫助!
import 'dart:mirrors';
class A<T> {
T item;
List<T> items;
}
main() {
var m = reflectType(new A<int>().runtimeType);
var itemType = m.declarations[#item].type as TypeMirror;
print('type of #item: ${itemType.qualifiedName}'); // type of #item: ClassMirror on 'int'.
var itemsType = m.declarations[#items].type as ClassMirror;
print('type of #items: ${itemsType.qualifiedName}'); // type of #items: ClassMirror on 'List'.
print('type arguments of #items: ${itemsType.typeArguments.map((t) => t.qualifiedName)}'); // type arguments of #items: [TypeVariableMirror on 'T'].
}
謝謝!反應非常明確 – matth3o 2014-11-06 18:07:36
似乎是http://stackoverflow.com/questions/14384865 – 2014-11-06 17:31:34
沒錯的副本...但你的反應是比較直接的。 – matth3o 2014-11-06 18:09:09