The type org.eclipse.jdt.annotation.NonNull cannot be resolved. It is indirectly referenced from required .class files

强颜欢笑 提交于 2019-12-03 05:40:56

问题


When I use the Java 8 method reference double colon operator (::) with new operator (e.g. MyType::new), I get this error in Eclipse of Spring Tool suite (STS):

The type org.eclipse.jdt.annotation.NonNull cannot be resolved. It is indirectly referenced from required .class files

How to get rid of this error?


回答1:


Error description is provided in Stephan Herrmann's comment. There is open Eclipse issue to make this issue more user friendly.

Solution is to include following dependency:

<dependency>
    <groupId>org.eclipse.jdt</groupId>
    <artifactId>org.eclipse.jdt.annotation</artifactId>
    <version>2.0.0</version>
</dependency>



回答2:


Eclipse has a feature called annotation-based null analysis, which provides compile-time checks using annotations (e.g. @NonNull or @Nullable). You get this error when annotations are missing in the classpath.

If you don't plan to use the annotation-based null analysis feature, you can just disable it in Eclipse.

Open the global or project settings and go to Java > Compiler > Warnings. In the Null analysis category, uncheck Enable annotation-based null analysis. Then rebuild the workspace and those errors won't show again.




回答3:


I have solved it by changing the "Use default annotation for null specifications"

I have enter the both class names:

javax.annotation.Nonnull
javax.annotation.Nullable


来源:https://stackoverflow.com/questions/33785727/the-type-org-eclipse-jdt-annotation-nonnull-cannot-be-resolved-it-is-indirectly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!