Model 3 classfile design document
Brian Goetz
brian.goetz at oracle.com
Fri Feb 12 09:34:22 UTC 2016
> Will the template class be accessible as a java/lang/Class (or equivalent) in its unspecialized form? If so, will any of the type variable information be made available through this class? We're wondering how much information needs to be stored in our class objects.
For compatibility reasons, Constant_CLASS[Foo] and Constant_ParamType[Foo, erased*] resolve to the same class — legacy classfiles will ask for erased Foo as a Class.
Reflection will have to be able to recover whatever information was present in the parameterization. For reified parameterizations, this should be easy enough; for erased parameterizations, reflection will answer “erased” when asked about “what is E in ArrayList<String>”. But, it seems safe to assume that, for a class with a GenericClass attribute for non-reified parameters, the answer will be ‘erased’.
>
> The document uses the example where an Outer class' type variable is propagated into the Inner class' GenericClass attribute.
Yes. A non-static inner class of a generic class is generic, even if it has no type parameters of its own. (The enclosing type parameters will be referenced at least from the synthetic constructor, which takes an instance of the enclosing class.)
> In this case:
>
> class Outer<any T> {
> class Inner {
> }
> }
>
> where Inner doesn't declare any type variables, my understanding is that Inner will still have the GenericClass attribute because it may refer to T. Will Inner still appear as the first class frame, with tvarCount=0, enforcing the rule that the first element is always the class itself?
Yes, that seems the most sensible way to do it.
More information about the valhalla-spec-observers
mailing list