失败的java断言失败的原因

问题描述 投票:0回答:2

可能是什么原因

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

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

java debugging exception error-handling exception-handling
2个回答
3
投票

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

Enable assertions


1
投票

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

默认情况下禁用断言。

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

here

© www.soinside.com 2019 - 2024. All rights reserved.