Disable @NotNull annotation when generating code
已回答
Hello,
Is there a way to disable insertion of @NotNull annotations when generating code such as overriding methods?
For example, in the code snippet below, I do not want the @NotNull annotation to be added to the MyFile constructor when using Generate / Override Methods... to generate this constructor.
import org.jetbrains.annotations.NotNull;
import java.io.File;
public class MyFile extends File {
public MyFile(@NotNull String pathname) {
super(pathname);
}
}
请先登录再写评论。
Hello,
The `@NotNull` annotation is
so it's considered as part of the type and you can't disable its presence while method override in your case.
Then, if I disable nullity inference, will @NotNull stop being inserted in generated methods? Is there a way to disable nullity inference?
Hello,
In case you have the annotation in base method, it's considered as part of the type thus is included in method that overrides the basic one. This behaviour is expected and can't be changed.
Hello,
In this case,
The org.jetbrains.annotations.NotNull annotation is not in the base method. The base constructor, File(String pathname), is defined in the JDK and cannot have been annotated with org.jetbrains.annotations.NotNull. However, the annotation is still added when overriding the method. How should I understand this? Is it a bug?
Hello,
Sorry, I got you wrong. Here is the link to the issue created at YouTrack for your report:
https://youtrack.jetbrains.com/issue/IDEA-279583
Please follow.
Great! Following the issue. Thanks a lot!