且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用断言在Android的?

更新时间:2023-01-23 13:23:04

因为大部分时间一个人是不是在调试模式下运行,而一些优化code在Android的断言将无法正常工作。因此,正确的解决方法是手动抛出一个异常,用code是这样的:

Assert won't work in Android because most of the time a person isn't running in debug mode, but rather some optimized code. Thus, the proper solution is to manually throw an exception, with code like this:

if (obj==null) throw new AssertionError("Object cannot be null");