Java. Which @Nullable should I use to mark return value with one?

Viewed 3224

My java method can return null and non null results. I want mark method with @Nullable annotation to make it more readable.

I used com.sun.istack.internal.Nullable but sonar says Classes from "sun.*" packages should not be used. Code smell Major squid:S1191.

I try to find more similar annotations, but there are variants from different IDE, not from java vendor.

Does java (oracle) provides alternatives for nullable annotation or I should use third party libraries only? If I have to use third party library to have an @Nullable which one should be good?

4 Answers

Optional<T> or @Nullable or @return tag from java-doc are ways to say to users of your API that a method can return null. But you mentioned in comments that your method is private. It means that nobody, except you, can use it. That's why no additional stuff needed.

Related