[cdi-dev] Mutable annotation literals
struberg at yahoo.de
Thu Aug 16 08:18:53 EDT 2012
Imo we don't need to cache the hashCode in the AnnotationLiteral itself. We just need to cache if there are value methods or not. If not, then we can immediately return 0. If there are value methods present, then you need to extend the AnnotationLiteral class anyway and can add an own hashCode which delegates to super.hashCode() and caches the result if the values will not be changed.
----- Original Message -----
> From: Pete Muir <pmuir at redhat.com>
> To: cdi-dev <cdi-dev at lists.jboss.org>
> Sent: Thursday, August 16, 2012 1:43 PM
> Subject: [cdi-dev] Mutable annotation literals
> Marko has added caching for the hashcode value on AnnotationLiteral, which is
> based on the premise that an AnnotationLiteral is not mutable.
> This is a reasonable thing to require (as real annotations are normally
> immutable!) and a very good optimisation, however it is not backwards
> compatible, as we have not previously required AnnotationLiteral to be
> An alternative option is to introduce the ImmutableAnnotationLiteral subclass,
> which would require any concrete instances to be immutable and could use this
> optimisation. We could "deprecate" AnnotationLiteral (as described in
> Note that regardless, we can apply the minor optimisation suggested by Mark,
> that we return 0 if the annotation has no members.
> cdi-dev mailing list
> cdi-dev at lists.jboss.org
More information about the cdi-dev