RequireNonNull and @nonnull in Android
RequireNonNull and @nonNULL in Android do not solve the problem of error reporting. Instead, they are designed to throw and locate problems faster.
Question 1: requireNonNull will throw an exception without object.requirenonNULL. Why?
A: This is because of the idea of fail-fast, which translates as allowing bugs to appear as early as possible so that developers can quickly locate bugs, rather than having deep nested bugs that occur and then troubleshoot.
Question 2: What does @nonnull do?
A: @nonNULL is used to prompt the compiler and does not really prevent NullPointerExceptions. For example, if null is passed after declaring a variable, the compiler will prompt Passing ‘null’ argument to parameter annotated as @null