How to use @Nullable and @Nonnull annotations more effectively?

后端 未结 9 444
你的背包
你的背包 2020-12-12 12:01

I can see that @Nullable and @Nonnull annotations could be helpful in preventing NullPointerExceptions but they do not propag

9条回答
  •  执笔经年
    2020-12-12 13:05

    Short answer: I guess these annotations are only useful for your IDE to warn you of potentially null pointer errors.

    As said in the "Clean Code" book, you should check your public method's parameters and also avoid checking invariants.

    Another good tip is never returning null values, but using Null Object Pattern instead.

提交回复
热议问题