Hi Alan, > You will find places in the JDK code, esp. in performance critical code, > where assertions are commented out. The reason is that asserts, even if > disabled, increase the method size and can impact inlining by the > compiler at run-time. So while useful when debugging some issue in such > code, they are commended out to avoid increasing the method size.
Thanks a bunch! I didn't realize this before! > Asserts are very useful during development or when testing, e.g. the JDK > tests run with -esa and can periodically help catch issues when testing > a change. Indeed. But I am a little bit curious: unlike C/C++, which enables assert by default (You could define NDEBUG to disable it during compilation), Java disables assert by default. I wonder why the language designers made such a decision. Is it for backward compatibility? IMHO, enabling it by default might potentially increase its usage among developers. Regards, Daohan