失败的java断言失败的原因

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了失败的java断言失败的原因相关的知识,希望对你有一定的参考价值。

可能是什么原因

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

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

答案

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

Enable assertions

另一答案

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

默认情况下禁用断言。

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

here

以上是关于失败的java断言失败的原因的主要内容,如果未能解决你的问题,请参考以下文章