5

I'm new to Java and just discovered the @Nullable and other such annotations, so I tried them.

I first tried the ones included in Eclipse, but they didn't allow me to use them for fields, and that made me think some fields could be null whereas they clearly couldn't.

By the way, I was using the thing to make everything @NonNull by default.

Then, I tried findbugs (edu.umd.cs.findbugs.annotations), but apparently, the whole thing is deprecated ( http://findbugs.sourceforge.net/api/edu/umd/cs/findbugs/annotations/package-summary.html ).

What am I supposed to use?

Pang
  • 9,564
  • 146
  • 81
  • 122
xavierm02
  • 8,457
  • 1
  • 20
  • 24

1 Answers1

5

When something is marked as @Deprecated, an alternative will usually be provided in the Javadoc for the deprecated declaration.

In this case, the HTML-formatted Javadoc is failing you: it's not showing the fully-qualified class name of the alternative, so you see something like

Nullable: Deprecated. -Use Nullable instead

Which isn't very helpful.

So let's look at the source for Nullable.java instead:

/**
 * The annotated element could be null under some circumstances.
 * 
 * ...
 * 
 * @deprecated - use {@link javax.annotation.Nullable} instead. 
 **/

Aha: It's javax.annotation.Nullable we're supposed to use instead. But this is a bigger question. I suggest you look here: Which @NotNull Java annotation should I use?

Community
  • 1
  • 1
Mark Peters
  • 80,126
  • 17
  • 159
  • 190