import 'dart:mirrors';
class Test1 {
final test = 'test1';
}
class Test2 {}
void main() {
List<dynamic> list = [Test1, Test2];
print(list);
dynamic test = list[0];
print(Test1);
print(test);
// print(test[Symbol('')]);
ClassMirror classMirror = reflectClass(test);
print(classMirror);
var newInstance=classMirror.newInstance(Symbol(''),[]);
print(newInstance);
print(newInstance.getField(Symbol('test')));
print(newInstance.reflectee);
print(Test1());
print(newinstance.reflectee.test);
print(Test1().test);
}
不过flutter下不支持dart:mirrors
https://github.com/flutter/fl...
类似问题中那种动态的newInstance代码应该是实现不了的
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…