question on type annotations in lambda expression
Steve Sides
steve.sides at oracle.com
Wed Mar 6 11:47:31 PST 2013
As a note, if i put the same annotations on the getString() methods, I
see 4(2+2) in both T14$1inner and T14l$1inner, so it's just on fields.
-steve
On 3/6/2013 11:39 AM, Steve Sides wrote:
> Hi Werner,
> I have a question on type annotations in lambda expressions.
> Are these not analogous in their annotations? One is a local class and
> another a local class in a lambda expression.
> Only the type-annotations show up in the lambda expression.
>
> In T14$1inner there are 2 TypeAnnotations and 2 Annotations.
> java.lang.Class<?> icc;
> descriptor: Ljava/lang/Class;
> flags:
> Signature: #10 // Ljava/lang/Class<*>;
> RuntimeVisibleAnnotations:
> 0: #12()
> 1: #13()
> RuntimeVisibleTypeAnnotations:
> 0: #12(): FIELD
> 1: #13(): FIELD
>
> In T14l$1inner(lambda expression) there are 2 TypeAnnotations and 0
> Annotations.
> java.lang.Class icc;
> descriptor: Ljava/lang/Class;
> flags:
> RuntimeVisibleTypeAnnotations:
> 0: #10(): FIELD
> 1: #11(): FIELD
>
> source:
>
> import java.lang.annotation.*;
> import static java.lang.annotation.RetentionPolicy.*;
> import static java.lang.annotation.ElementType.*;
> import java.util.List;
> import java.util.ArrayList;
>
> class T14{
> void test() {
> class innerClass {
> @A @B Class<?> icc; //2 Ann, 2 TypeAnn
> innerClass(Class<?> _c) { icc = _c; } //2 TypeAnn
> String getString() { return icc.toString(); } //2
> Ann,2TypeAnn
> }
> String s = new innerClass(T14.class).getString();
> System.out.println(s);
> }
> }
>
> //Source2:
> class T14l{
> interface MapFun<T, R> { R m( T n); }
> MapFun<Class<?>,String> cs;
>
> void test() {
> cs = c -> {
> class innerClass {
> @A @B Class<?> icc; //2 Ann, 2 TypeAnn
> innerClass(Class<?> _c) { icc = _c; } //2 TypeAnn
> String getString() { return icc.toString(); } //2
> Ann,2TypeAnn
> }
> return new innerClass(c).getString();
> };
> System.out.println("cs.m : " + cs.m(Integer.class));
> }
> }
>
> // annotations
> @Retention(RUNTIME)
> @Target({TYPE_USE,TYPE,FIELD,METHOD,PARAMETER,CONSTRUCTOR,LOCAL_VARIABLE,ANNOTATION_TYPE,PACKAGE})
> @Repeatable( AC.class ) @interface A { }
> @Retention(RUNTIME)
> @Target({TYPE_USE,TYPE,FIELD,METHOD,PARAMETER,CONSTRUCTOR,LOCAL_VARIABLE,ANNOTATION_TYPE,PACKAGE})
> @interface AC { A[] value(); }
> @Retention(RUNTIME)
> @Target({TYPE_USE,TYPE,FIELD,METHOD,PARAMETER,CONSTRUCTOR,LOCAL_VARIABLE,ANNOTATION_TYPE,PACKAGE})
> @Repeatable( BC.class ) @interface B { }
> @Retention(RUNTIME)
> @Target({TYPE_USE,TYPE,FIELD,METHOD,PARAMETER,CONSTRUCTOR,LOCAL_VARIABLE,ANNOTATION_TYPE,PACKAGE})
> @interface BC { B[] value(); }
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/type-annotations-dev/attachments/20130306/85be3e09/attachment.html
More information about the type-annotations-dev
mailing list