失败的java断言失败的原因

时间:2017-12-19 16:20:00

标签: java debugging exception error-handling exception-handling

可能是什么原因

assert(false); //this should fail but doesn't

//this gets executed but shouldn't
if(!false) throw new IllegalStateException("what's the bloody point?!!");

抛出IllegalStateException而不是AssertionError

是的,我在代码中就有这两行。

2 个答案:

答案 0 :(得分:3)

默认情况下,在运行时禁用断言,您需要提供-ea或-enableassertions JVM标志

Enable assertions

答案 1 :(得分:1)

唯一合理的答案是你在没有断言的情况下执行。

默认情况下禁用断言。

执行时,需要使用-ea对JVM进行参数化。

here