Enum Class Nullness

java.lang.Object
java.lang.Enum<Nullness>
org.springframework.core.Nullness
All Implemented Interfaces:
Serializable, Comparable<Nullness>, Constable

public enum Nullness extends Enum<Nullness>
Constants that indicate nullness, as well as related utility methods.

Nullness applies to type usage, a field, a method return type, or a parameter. JSpecify annotations are fully supported, as well as Kotlin null safety, @Nullable annotations regardless of their package, and Java primitive types.

JSR-305 annotations as well as Spring null safety annotations in the org.springframework.lang package such as @NonNullApi, @NonNullFields, and @NonNull are not supported by this API. However, @Nullable is supported via the package-less check. Migrating to JSpecify is recommended.

Since:
7.0
Author:
Sebastien Deleuze
  • Enum Constant Details

    • UNSPECIFIED

      public static final Nullness UNSPECIFIED
      Unspecified nullness (Java default for non-primitive types and JSpecify @NullUnmarked code).
    • NULLABLE

      public static final Nullness NULLABLE
      Can include null (typically specified with a @Nullable annotation).
    • NON_NULL

      public static final Nullness NON_NULL
      Will not include null (Kotlin default and JSpecify @NullMarked code).
  • Method Details

    • values

      public static Nullness[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static Nullness valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • forMethodReturnType

      public static Nullness forMethodReturnType(Method method)
      Return the nullness of the return type for the given method.
      Parameters:
      method - the source for the method return type
      Returns:
      the corresponding nullness
    • forParameter

      public static Nullness forParameter(Parameter parameter)
      Return the nullness of the given parameter.
      Parameters:
      parameter - the parameter descriptor
      Returns:
      the corresponding nullness
    • forMethodParameter

      public static Nullness forMethodParameter(MethodParameter methodParameter)
      Return the nullness of the given method parameter.
      Parameters:
      methodParameter - the method parameter descriptor
      Returns:
      the corresponding nullness
    • forField

      public static Nullness forField(Field field)
      Return the nullness of the given field.
      Parameters:
      field - the field descriptor
      Returns:
      the corresponding nullness