How to programmatically enable assert?
问题 How can I programmatically enable assert for particular classes, instead of specifying command line param "-ea"? public class TestAssert { private static final int foo[] = new int[]{4,5,67}; public static void main(String []args) { assert foo.length == 10; } } 回答1: This was a comment to @bala's good answer, but it got too long. If you just enable assertions then call your main class--your main class will be loaded before assertions are enabled so you will probably need a loader that doesn't