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