Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create an Instance of a Class Whose Name Will Be Supplied at Runtime #15519

Closed
DartBot opened this issue Dec 8, 2013 · 2 comments
Closed

Create an Instance of a Class Whose Name Will Be Supplied at Runtime #15519

DartBot opened this issue Dec 8, 2013 · 2 comments
Labels
area-library closed-not-planned Closed as we don't intend to take action on the reported issue library-mirrors type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Dec 8, 2013

This issue was originally filed by jan.d...@gmail.com


Now to I can create dart instace dynamically this way:

ClassMirror mirror = reflectClass(Example);
var newInstance = mirror.newInstance(const Symbol(''), []).reflectee;

I would like to see something like this:

 ClassMirror mirror = reflectClass("full.qualified.path.Example");
var newInstance = mirror.newInstance(const Symbol(''), []).reflectee;

I wan to use it for strongly typed IO operations.

Enclosing similar syntax from Java:

Class mirror = Class.forName("full.qualified.path.Example");
full.qualified.path.Example newInstance = (full.qualified.path.Example) mirror.newInstance();

@DartBot
Copy link
Author

DartBot commented Dec 8, 2013

This comment was originally written by jan.dur...@gmail.com


Sorry, this is not a defect, I just haven't found a way how to submit it as enhancement.

@lrhn
Copy link
Member

lrhn commented Dec 9, 2013

Names are not necessarily unique in Dart, not even fully qualified names. They are in Java (per class-loader at least).
That means that it's unlikely that we can use the name to find the class in a unique way.

This sounds more like a job for a utility function that uses the mirror library to search for a matching library and class name. Or even find more than one, if that many exists.


Removed Type-Defect label.
Added Type-Enhancement, Area-Library, Library-Mirrors, Triaged labels.

@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed priority-unassigned labels Feb 29, 2016
@lrhn lrhn added the closed-not-planned Closed as we don't intend to take action on the reported issue label Sep 14, 2020
@lrhn lrhn closed this as completed Sep 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-library closed-not-planned Closed as we don't intend to take action on the reported issue library-mirrors type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

3 participants