RFR: 8335927: Revisit AnnotationConstantValueEntry and AnnotationValue.OfConstant

Adam Sotona asotona at openjdk.org
Fri Aug 2 08:00:32 UTC 2024


On Fri, 2 Aug 2024 00:39:12 GMT, Chen Liang <liach at openjdk.org> wrote:

> 1. Add notes and docs about the difference between resolved constants and constant pool descriptors for annotation constants (e.g. `char` vs `IntegerEntry`)
> 2. Improved value specification to specify their tags.
> 3. Improved value factories to return their specific types instead of `OfConstant`
> 4. Improved value classes to return specific `PoolEntry` subtypes and specific live constant subtypes
> 5. Removed confusing and meaningless `ConstantPoolBuilder.annotationConstantValueEntry`

src/java.base/share/classes/java/lang/classfile/AnnotationValue.java line 90:

> 88:      */
> 89:     @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
> 90:     sealed interface OfConstant<C extends AnnotationConstantValueEntry, R extends Comparable<R> & Constable>

I suggest to minimize use of generics in combination with sealed interface trees and pattern matching. It does not give many benefits, it takes out a part of the code readability and adds many unnecessary brackets and questionmarks: 

case AnnotationValue.OfConstant<?, ?> oc ->


`<R extends Comparable<R> & Constable>` at least brings a benefit of types combination. However I still think it does not outweigh the generics use cost. None of the generics parameter is near to orthogonal to the `OfConstant` nor critical for the API to operate.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/20436#discussion_r1701457480


More information about the compiler-dev mailing list