Assuming I have Java code like this:
package test;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
public class Test {
@NotNull
public static Object object() {
return new Object();
}
public static void test() {
object();
}
}
@Target({ ElementType.METHOD, ElementType.TYPE_USE })
@interface NotNull {}
When I use the quick fix (Ctrl+1) action "Assign statement to new local variable" on the "object();" call, I'm getting this:
public static void test() {
@NotNull
Object object = object();
}
I don't want the annotation in my client Java code as it's just noise for me. How can I prevent it from being generated all the time, and get this instead?
public static void test() {
Object object = object();
}
All of this only happens when the annotation has @Target(TYPE_USE), and only when org.eclipse.jdt.core.compiler.compliance=8 or later in .settings/org.eclipse.jdt.core.prefs
For the record, I've also filed enhancement request 565463.
(The real world API is declaring such annotations for better Kotlin interoperability (the JetBrains annotations are used), as Kotlin can use it to distinguish between T and T?, and avoid T!)