[JSR308] Nullness checker and generic checkNotNull function
Artemus Harper
subanark at gmail.com
Tue Jan 20 12:23:15 EST 2009
This is mostly likely a problem with generics as they are currently
not fully supported in the framework. There is a confusion between the
annotations on the generic definition and those on its use (the
framework is attempting to apply @Nullable and @NonNull to all T). You
might be able to work around this by using multiple generic names.
Although I don't have the current build on hand you could try:
public static <T,E extends T> @NonNull E checkNotNull(@Nullable T
object)
On Jan 19, 2009, at 10:16 AM, Piotr Zielinski wrote:
> Hi,
>
> 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?
>
> Thanks,
> Piotr
>
> _______________________________________________
> JSR308 mailing list
> JSR308 at lists.csail.mit.edu
> https://lists.csail.mit.edu/mailman/listinfo/jsr308
More information about the JSR308
mailing list