public class Nullness extends Object
The class enables to remove checker-qual runtime dependency, and helps IDEs to see
the resulting types of castNonNull better
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
castNonNull(T ref)
Enables to threat nullable type as non-nullable with no assertions.
|
@Pure @EnsuresNonNull(value="#1") public static <T> T castNonNull(T ref)
It is useful in the case you have a nullable lately-initialized field like the following:
class Wrapper<T> { @Nullable T value; }.
That signature allows to use Wrapper with both nullable or non-nullable types:
Wrapper<@Nullable Integer> vs Wrapper<Integer>. Suppose you need to implement
T get() { return value; } The issue is checkerframework does not permit that
because T has unknown nullability, so the following needs to be used:
T get() { return sneakyNull(value); }
T - the type of the referenceref - a reference of @Nullable type, that is non-null at run timeCopyright © 2012-2021 Apache Software Foundation. All Rights Reserved.