Annotation Type NotNull


  • @Documented
    @Retention(CLASS)
    @Target({METHOD,FIELD,PARAMETER,LOCAL_VARIABLE})
    public @interface NotNull
    An element annotated with NotNull claims null value is forbidden to return (for methods), pass to (parameters) and hold (local variables and fields). Apart from documentation purposes this annotation is intended to be used by static analysis tools to validate against probable runtime errors and element contract violations.
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      java.lang.Class<? extends java.lang.Exception> exception  
      java.lang.String value  
    • Element Detail

      • value

        java.lang.String value
        Returns:
        Custom exception message
        Default:
        ""
      • exception

        java.lang.Class<? extends java.lang.Exception> exception
        Returns:
        Custom exception type that should be thrown when not-nullity contract is violated. The exception class should have a constructor with one String argument (message). By default, IllegalArgumentException is thrown on null method arguments and IllegalStateException — on null return value.
        Default:
        java.lang.Exception.class