a small lambda issue
Steve Sides
steve.sides at oracle.com
Tue Mar 12 12:12:54 PDT 2013
I know type-annotations (@Target(TYPE_USE,FIELD)) are noted as not the
best form, so I hate to say "normally..." :)
But, so far, when a type-annotation is targeted to TYPE_USE and FIELD,
I've been seeing two sets of annotations, RuntimeAnnotation(s) and
RuntimeTypeAnnotation(s).
On something like Test7a below, on Test7$1innerClass I would see
RuntimeVisibleAnnotations:
0: #12()
RuntimeVisibleTypeAnnotations:
0: #12(): FIELD
import java.lang.annotation.*;
import static java.lang.annotation.RetentionPolicy.*;
import static java.lang.annotation.ElementType.*;
class Test7a{
String itest() {
class innerClass {
@A Class<?> icc = null;
innerClass(Class<?> _c) { icc = _c; }
String getString() { return icc.toString(); }
}
return new innerClass(Test7a.class).getString();
}
void test() {
System.out.println(itest());
}
public static void main(String... args) {new Test7a().test(); }
}
@Retention(RUNTIME) @Target({TYPE_USE,FIELD}) @interface A { }
On what I think is an analogous situation for lambda, on
Test7$1innerClass I see only
RuntimeVisibleTypeAnnotations:
0: #10(): FIELD
class Test7{
interface MapFun<T, R> { R m( T n); }
MapFun<Class<?>,String> cs;
void test() {
cs = c -> {
class innerClass {
@A Class<?> icc = null;
innerClass(Class<?> _c) { icc = _c; }
String getString() { return icc.toString(); }
}
return new innerClass(c).getString();
};
System.out.println("cs.m : " + cs.m(Integer.class));
}
public static void main(String... args) {new Test7().test(); }
}
@Retention(RUNTIME) @Target({TYPE_USE,FIELD}) @interface A { }
-steve
More information about the type-annotations-dev
mailing list