Android @NonNull usefulness

前端 未结 3 2164
生来不讨喜
生来不讨喜 2021-02-12 09:40

After a few reading and questions like this one I was wondering if there was a point in using @NonNull Android Support Annotation.

I can see a very small war

3条回答
  •  北荒
    北荒 (楼主)
    2021-02-12 10:23

    Its main purpose is informational to your coworkers. One person is never the sole programmer of a large project. Using NotNull tells other programmers that the contract of the function means you can never send a null to it, so they don't do it. Otherwise I may make a logical assumption that calling setFoo(null) will clear Foo, whereas the API can't handle not having a Foo.

提交回复
热议问题