Search code examples
javaeclipseguavanullable

In which cases I should use @Nullable annotation?


I investigate guava library for java.

reading different materials I faced with @Nullable annotation.

I added guava jar file to classpath but my IDE(eclipse) say:

Nullable cannot be resolved to a type

But if I ctrl + click on Nullable I see blue underline and see next after:

source not found

maybe it is problem with eclipse - I don't know and this annotation located in another location.

But additionally I cannot understand situation when I should to use this annotation.


Solution

  • It is in here.

    javax.annotation.Nullable
    

    I think you need this jar: jsr305.jar.

    See also:

    https://jcp.org/en/jsr/detail?id=305

    http://jsr-305.googlecode.com/svn/trunk/javadoc/javax/annotation/package-tree.html

    Regarding when you should use it - check this link.

    @Nullable annotation usage