A simpler model for repeating annotations

Alex Buckley alex.buckley at oracle.com
Tue Jan 8 13:45:54 PST 2013


It would be possible to add a default to Repeatable's value element and 
to introduce AnnotationContainer, sure.

Alex

On 1/8/2013 1:43 PM, Ali Ebrahimi wrote:
> Hi,
> you mean this changes is not in scope of java 8. can we make current
> proposal forward compatible for such changes in future?
>
> Ali
>
> On Tue, Jan 8, 2013 at 11:24 PM, Alex Buckley <alex.buckley at oracle.com
> <mailto:alex.buckley at oracle.com>> wrote:
>
>     Sharing a single containing annotation type between multiple
>     repeating annotation types is not unreasonable. However, it
>     fundamentally relies on annotation subtyping, which was not in scope
>     for JEP 120.
>
>     Alex
>
>
>     On 1/8/2013 3:17 AM, Ali Ebrahimi wrote:
>
>         Hi Alex,
>         I think, I'm late to list.
>         The following is just my 2 cent suggestion to your proposal.
>
>         1) Introduce AnnotationContainer annotation in java.lang package
>         (java
>         se 8 ) as default container for repeating annotations:
>
>         @interface AnnotationContainer{ Annotation[] value(); }
>         (relax rules of jls 9.6.1 to include Annotation (class) type)
>
>         2) Modify Repeatable annotation:
>         @interface Repeatable{ Class<? extends Annotation> value() default
>         AnnotationContainer.class; }
>
>         with 1, 2 in mind we have one standard default container
>         annotation for
>         all repeating annotations that don't specify containing
>         annotation. This
>         allows to package all repeating annotations in one container
>         annotation
>         and reduce static and dynamic footprint. In other side,
>         developer don't
>         need to introduce one containing annotation for each repeating
>         annotations, this also reduce number of class files and makes this
>         feature of java 8 user friendly for developer. developer just need
>         annotate repeating annotations with Repeatable annotation.
>
>         example:
>
>         @Repeatable
>         @interface Foo { int value(); }
>
>         @Repeatable
>         @interface Bar{}
>
>         @Repeatable(AliContainer.__class)
>         @interface Ali{ String value();}
>
>         @interface AliContainer{ Ali[] value(); }
>
>
>         @Foo(1) @Foo(2) @Bar @Bar @Ali("java lover") @Ali("Flying on the
>         Clouds")
>         class A {}
>
>         in class file:
>
>         @AnnotationContainer({@Foo(1), @Foo(2), @Bar, @Bar})
>         @AliContainer({@Ali("java lover"), at Ali("Flying on the Clouds")})
>         class A {}
>
>
>         Regards,
>         Ali Ebrahimi
>
>



More information about the enhanced-metadata-spec-discuss mailing list