【问题标题】:Causes for non-failing failing java assertions非失败 java 断言失败的原因
【发布时间】:2018-06-02 03:07:50
【问题描述】:

可能是什么原因

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


    【解决方案1】:

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

    默认情况下禁用断言。

    您需要在执行时使用-ea 参数化JVM。

    here

    【讨论】:

      【解决方案2】:

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

      Enable assertions

      【讨论】:

        猜你喜欢
        • 2016-04-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-08-11
        • 1970-01-01
        • 1970-01-01
        • 2011-05-27
        相关资源
        最近更新 更多