How to use assert in android?

后端 未结 6 2236
日久生厌
日久生厌 2020-12-08 09:35

I want to use assert obj != null : \"object cannot be null\" on Android device. The assert doesn\'t seem to work, so I searched online and I found this local so

6条回答
  •  Happy的楠姐
    2020-12-08 09:56

    Create your own assert method:

    public static  T assertNotNull(T object) {
        if (object == null)
            throw new AssertionError("Object cannot be null");
        return object;
    }
    

    Returning same object allows for using this in assignments for brevity.

提交回复
热议问题