答案 0 :(得分:7)
public static boolean areAssertsEnabled() {
boolean assertsEnabled = false;
assert assertsEnabled = true; // Intentional side effect!!!
return assertsEnabled;
}
答案 1 :(得分:5)
boolean assertEnabled = false;
try {
assert false;
} catch (AssertionError e) {
assertEnabled = true;
}
答案 2 :(得分:4)
ManagementFactory.getRuntimeMXBean().getInputArguments().contains("-ea");