Annotation cycles

Roel Spilker r.spilker at gmail.com
Thu Apr 19 15:30:39 PDT 2012


Yes, our proposal and implementation also supports

@interface A {
  Annotation[] value();
}

The implementation is pretty simple and you can already test it in java7 if
you use the jar from the page I sent.

The two main pieces of code were:
- The cycle-checking. Previously only the return type of the annotation
methods needed to be checked. Now also the default values
- The runtime proxy code became a bit more involved.

Regarding the cycles in the annotations: as long as you don't depend on
default values inside default values, you're in the clear. In other words,
you could break the cycle by providing an explicit value instead. This can
be checked compile-time.

Roel

On Tue, Apr 17, 2012 at 5:59 PM, David M. Lloyd <david.lloyd at redhat.com>wrote:

> Arrays too?
>
>
> On 04/17/2012 10:42 AM, Roel Spilker wrote:
>
>> And while you're at it, we have another proposal ready to be pushed
>> allowing any annotation to be the result of an annotation method:
>>
>> @interface A {
>>   Annotation value();
>> }
>>
>> See http://projectlombok.org/**anyannotation/<http://projectlombok.org/anyannotation/>
>>
>> The required changes to both specs and implementation are very small.
>> All the work has bene done already, albeit based on the jdk7 source. the
>> only things missing are a JEP, TCK and updating it to the current state
>> of JDK8.
>>
>> Roel
>>
>> On Tue, Apr 17, 2012 at 2:59 PM, Jesse Glick <jesse.glick at oracle.com
>> <mailto:jesse.glick at oracle.com**>> wrote:
>>
>>    On 03/11/2012 06:19 PM, Joe Darcy wrote:
>>
>>        two annotation types cannot be containers for each other because
>>        that would create an illegal cyclic annotation type situation
>>
>>
>>    So long as you are changing the language spec for annotations, why
>>    not fix this longstanding irritation too (#6264216), which
>>    arbitrarily prevents a rather wide range of use cases for
>>    annotations? For example, move the cycle check from declaration time
>>    to use time, so that the only rejected constructs would be genuinely
>>    nonterminating cycles that no one would ever intentionally write:
>>
>>    @interface A {
>>      B[] bs() default {@B};
>>    }
>>    @interface B {
>>      A as() default {@A};
>>    }
>>    @A class X {} // oops
>>
>>    but so that legitimate cases compile:
>>
>>    @interface A {
>>      B[] bs() default {};
>>    }
>>    @interface B {
>>      A[] as() default {};
>>    }
>>    @A(@B(@A)) class X {} // fine
>>
>>
>>
>
> --
> - DML
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20120420/ad714c40/attachment.html 


More information about the compiler-dev mailing list