Java – @Nullable annotation usage

annotationsjava

I saw some method in java declared as:

void foo(@Nullable Object obj)
{ ... }

What's the meaning of @Nullable here? Does it mean the input could be null?

Without the annotation, the input can still be null, so I guess that's not just it?

Best Answer

It makes it clear that the method accepts null values, and that if you override the method, you should also accept null values.

It also serves as a hint for code analyzers like FindBugs. For example, if such a method dereferences its argument without checking for null first, FindBugs will emit a warning.