从Dart中的字符串创建通用类的实例? [英] Create an instance of an Generic Class from a String in Dart?
本文介绍了从Dart中的字符串创建通用类的实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,从这里我知道我可以从一个字符串创建一个实例:
Hello from here I know that I can create an instance from a String:
How to get a Class name dynamically (from a string) in Dart, then create an instance?
但是如何从String中创建一个Generic类的实例,例如:
but How do I create an instance of a Generic class from a String, ie:
var class_name = "GenericController<Book>"; // user input here
new class_name();
推荐答案
这是目前不可能的(因为你可能注意到了) 。在Dart问题跟踪代码中有一个打开的案例,您应该在星标中显示您的兴趣:
This is not currently possible (as you probably noticed). There's an open case in the Dart issue tracker you should Star to show your interest:
https://code.google.com/p/dart/issues/detail?id=12921
这篇关于从Dart中的字符串创建通用类的实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文