Right way to use the @NonNull annotation in Android Studio

前端 未结 3 973
甜味超标
甜味超标 2020-12-29 22:20

I\'d like to use the @NonNull annotation in Android, but I can\'t figure out just the right way to do it. I propose you this example:

public voi         


        
3条回答
  •  北荒
    北荒 (楼主)
    2020-12-29 22:37

    You can use the comment-style suppression to disable that specific null check warning, e.g.:

        public MyMethod(@NonNull Context pContext) {
            //noinspection ConstantConditions
            if (pContext == null) {
                throw new IllegalArgumentException();
            }
            ...
        }
    

    You'll need that //noinspection ConstantConditions every time you do it.

提交回复
热议问题