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

[Qestion][Enhancement] Why ClassMirror<T> is not a generic type like Class<T> in C# or Java? #157

Open
Guang1234567 opened this issue Jan 2, 2019 · 2 comments

Comments

@Guang1234567
Copy link

Hello dev:

For example:

class A{}

main() {
ClassMirror<A> classMirror = myReflectable.reflectType(A);  // want ClassMirror<A>  that have static type check !!! 

foo(ClassMirror<A> clazzOfA) {
     print(clazzOfA.invoke("oneArgument", [84])); // do sth with class of A
}
}
//in java

Class<A> class = A.getClass();  // have static type check 
//...
@Guang1234567 Guang1234567 changed the title Why ClassMirror<T> is a generic type like Class<T> in C# or Java? Why ClassMirror<T> is nota generic type like Class<T> in C# or Java? Jan 2, 2019
@Guang1234567 Guang1234567 changed the title Why ClassMirror<T> is nota generic type like Class<T> in C# or Java? Why ClassMirror<T> is not a generic type like Class<T> in C# or Java? Jan 2, 2019
@Guang1234567 Guang1234567 changed the title Why ClassMirror<T> is not a generic type like Class<T> in C# or Java? [Qestion][Enhanceman] Why ClassMirror<T> is not a generic type like Class<T> in C# or Java? Jan 2, 2019
@Guang1234567 Guang1234567 changed the title [Qestion][Enhanceman] Why ClassMirror<T> is not a generic type like Class<T> in C# or Java? [Qestion][Enhancement] Why ClassMirror<T> is not a generic type like Class<T> in C# or Java? Jan 2, 2019
@eernstg
Copy link
Collaborator

eernstg commented Jan 4, 2019

We have discussed a similar proposal for the core class Type, where we would give it a type argument and let the Type instance which reifies the type T be an instance of a class that implements Type<T>, also motivated by the improved static safety.

So it's a useful feature. But it would not be possible to implement this in reflectable (that is, using regular Dart code, because reflectable is based on code generation) unless/until we have support for some additional features in this area in the core.

In particular, if you use reflector.reflect(myObject).type where myObject is an instance of C<T> for some type T, we must return a ClassMirror<T>. But there is no way to create such a mirror, except by putting code into the body of C where its type argument is in scope. We cannot do that; for instance, C could be the built-in class int, and code generation doesn't have the ability to edit class int; or C could simply be a class in some third-party package, and reflectable doesn't get to edit any such libraries (and we don't want to give reflectable the ability to edit third party libraries, even if it might technically be possible).

So I'll mark this issue as blocked on the lack of support in core, and note that it would still be useful to keep it in mind in the situation where the addition of such features to the core is considered.

@Guang1234567
Copy link
Author

@eernstg

I see. Thanks your reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants