static final boolean assertionsEnabled = ;
if( assertionsEnabled )
assert expression1;
during debug build, the static final boolean is set to true. so that all the assertions can be enabled.
when compiling for release build, set the boolean to false. now since the boolean is final staic, all the assertion code will be unreachable. hence javac will result in no bytecode being formed for the assertion code. this will have a small perf benefit compared to when assertion bytecode exits and assertions are disabled.
No comments:
Post a Comment