JDK 13 RFR of JDK-8224687: Add clarifying overrides of Element.asType to more specific subinterfaces

Joe Darcy joe.darcy at oracle.com
Thu May 30 18:11:48 UTC 2019


Hi Ron,

On 5/30/2019 10:44 AM, Ron Shapiro wrote:
> Is it within scope to return the specific subtypes as covariant return 
> types? e.g. TypeParameterElement could return TypeVariable, 
> TypeElement could return DeclaredType, etc.
>
Based on experience with the earlier apt API, it was a conscious design 
choice for javax.lang.model to not use covariant returns in a case like 
this even though it seems appealing. The issue is the that the 
javax.lang.model is intended to be implemented by different compilers, 
including compilers where the native declaration and type hierarchies 
don't match the declaration and type hierarchies in the javax.lang.model 
modeling interfaces. In particular, some compilers might want to use a 
single type to implement many (or all) of the javax.lang.model.element 
interfaces. Having covariant overrides would interfere with such a 
reduced-type design.

HTH,

-Joe



More information about the compiler-dev mailing list