سؤال

When Guice says that it recognizes any @Nullable annotation here (http://code.google.com/p/google-guice/wiki/UseNullable) does that mean I can use com.sun.istack.internal.Nullable provided by the Java 7 Runtime successfully?

The fact that the package name is com.sun.istack.internal leads me to believe that I probably shouldn't be using it, but it is pretty convenient to use...

هل كانت مفيدة؟

المحلول 2

If null is permissible by your class, you can annotate the field or parameter with @Nullable. Guice recognizes any @Nullable annotation, like edu.umd.cs.findbugs.annotations.Nullable or javax.annotation.Nullable. —from the Guice site

To confirm chrylis's hunch above, Guice simply tests the name of the class.

// from core/src/com/google/inject/internal/Nullability.java
if ("Nullable".equals(type.getSimpleName())) {
  return true;
}

نصائح أخرى

You have to use Nullable from javax.annotation package as the example from the site says.

If you check comments on the site, there are links to proper jar library.

        <dependency>
            <groupId>com.google.code.findbugs</groupId>
            <artifactId>jsr305</artifactId>
            <version>3.0.2</version>
        </dependency>

In my case I was about to use Nullable annotation from IntelliJ package. :)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top