-
Notifications
You must be signed in to change notification settings - Fork 205
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
Allow instantiation of a Type object #1425
Comments
Note the similarity between this proposal and a very old discussion about supporting The creation of an instance of a class which is reified by a given instance of type So there are strong forces pushing you in the direction of using an approach like your function |
Thank you - this makes sense! I don't know a lot about mirrors, but if anyone else comes across this I've solved it like so: dynamic instantiate(Type type) {
ClassMirror mirror = reflectClass(type);
return mirror.newInstance(Symbol(''), []).reflectee;
} |
How about when you have |
Can't you just do |
Frankly not. It parses
|
Re-opening to serve as a canonical "request" issue for instantiating type variables. |
This issue seems to be about instantiating through a "Instantiating" a type variable means invoking a constructor of the underlying class of the type represented by the type variable. If you can do that, you can probably also invoke other static members. The one thing that makes constructors different is that they are necessarily and automatically "self typed", so a constructor on a type variable Any other static method is just typed somehow, by whatever constraints we allow you to write to ensure that the type even has a static method. Unless we introduce self-types into the type system in general. Guess I'm trying to say that there is a big family of related, but probably not equally viable, features here. |
Occasionally one needs to work with different types of object in different scenarios, frequently subclasses of the same type. I frequently have functions that I need to return them. My current solution looks like this:
A more elegant way of doing this, IMO, would be the ability to instantiate a Type with (), or the new keyword. Possibly we could also add a generic parameter for Type? Syntax could look like this:
The text was updated successfully, but these errors were encountered: