[JSR308] Nullness checker and generic checkNotNull function

Piotr Zielinski piotr.zielinski at gmail.com
Mon Jan 19 13:16:30 EST 2009


I'm trying to implement a generic checkNotNull function along the lines of

public static <T> @NonNull T checkNotNull(@Nullable T object) {
  if (object == null) {
    throw new NullPointerException();
  } else {
    return object;

The intention is to provide a fail-fast gateway between annotated and
non-annotated parts of my project code.  I've tried a few variants of
the checkNonNull method signature: they either don't compile or still
give nullability warning in expressions like (trivial)
checkNotNull((Object) null).  Could you help?


More information about the JSR308 mailing list