Eclipse e4 has much better support for null checks and resource tracking in the compiler.
Another solution is to write your own version of checkNotNull , for example:
@Nonnull public static <T> T checkNotNull(@Nullable T reference) { if (reference == null) { throw new NullPointerException(); } return reference; }
Now you can use this approach:
SomeAnnotation ann = Preconditions.checkNotNull( type.getAnnotation( SomeAnnotation.class ) );
(I missed the version of checkNotNull() , which accepts error messages, they work the same way).
I am wondering why Guava does not, as they already use this annotation elsewhere.
source share