Consider the following example
class Test {
@Target(ElementType.TYPE_USE)
@interface TypeAnno { }
@TypeAnno Supplier<String> r_f_i = () -> "r_f_i"; // ok
static @TypeAnno Supplier<String> r_f_s = () -> "r_f_s"; // ok
{
@TypeAnno Supplier<String> r_init_i = () -> "r_init_i"; // missing
}
static {
@TypeAnno Supplier<String> r_init_s = () -> "r_init_s"; // missing
}
void m() {
@TypeAnno Supplier<String> r_m_i = () -> "r_m_i"; // missing
}
static void g() {
@TypeAnno Supplier<String> r_g_s = () -> "r_g_s"; // missing
}
void h() {
t_cr(() -> "t_cr"); // ok
}
void i() {
t_no_cr((@TypeAnno Supplier<String>)() -> "t_no_cr"); // ok
}
void j() {
t_no_cr((java.io.Serializable & @TypeAnno Supplier<String>)() -> "t_no_cr"); // ok
}
void t_cr(@TypeAnno Supplier<String> r_p) { }
void t_no_cr(@TypeAnno Supplier<String> r_p) { }
}
This demonstrates the use of type annotations on variable declarations with a lambda initializer. By manually inspecting the AST, it's possible to see that the type annotations are missing in the lambda target type in the cases highlighted (local variable declaration).
class Test {
@Target(ElementType.TYPE_USE)
@interface TypeAnno { }
@TypeAnno Supplier<String> r_f_i = () -> "r_f_i"; // ok
static @TypeAnno Supplier<String> r_f_s = () -> "r_f_s"; // ok
{
@TypeAnno Supplier<String> r_init_i = () -> "r_init_i"; // missing
}
static {
@TypeAnno Supplier<String> r_init_s = () -> "r_init_s"; // missing
}
void m() {
@TypeAnno Supplier<String> r_m_i = () -> "r_m_i"; // missing
}
static void g() {
@TypeAnno Supplier<String> r_g_s = () -> "r_g_s"; // missing
}
void h() {
t_cr(() -> "t_cr"); // ok
}
void i() {
t_no_cr((@TypeAnno Supplier<String>)() -> "t_no_cr"); // ok
}
void j() {
t_no_cr((java.io.Serializable & @TypeAnno Supplier<String>)() -> "t_no_cr"); // ok
}
void t_cr(@TypeAnno Supplier<String> r_p) { }
void t_no_cr(@TypeAnno Supplier<String> r_p) { }
}
This demonstrates the use of type annotations on variable declarations with a lambda initializer. By manually inspecting the AST, it's possible to see that the type annotations are missing in the lambda target type in the cases highlighted (local variable declaration).