gpt4 book ai didi

java - 为每个包启用断言

转载 作者:搜寻专家 更新时间:2023-10-31 19:53:03 24 4
gpt4 key购买 nike

是否可以为每个包启用 Java 断言?我想在我的代码中使用断言,但与我的代码一起运行的其中一件事破坏了一些不相关的断言,作者拒绝修复它(至少现在,这不是严重错误)。

最佳答案

这是可能的,参见 http://docs.oracle.com/javase/7/docs/technotes/guides/language/assert.html#enable-disable

启用和禁用断言

To enable assertions at various granularities, use the -enableassertions, or -ea, switch. To disable assertions at various granularities, use the -disableassertions, or -da, switch. You specify the granularity with the arguments that you provide to the switch:

  • packageName...
    Enables or disables assertions in the named package and any subpackages.
  • ...
    Enables or disables assertions in the unnamed package in the current working directory.
  • className
    Enables or disables assertions in the named class

For example, the following command runs a program, BatTutor, with assertions enabled in only package com.wombat.fruitbat and its subpackages:

java -ea:com.wombat.fruitbat... BatTutor

您可以为所有包启用断言,然后为某些包禁用断言。或者 - 禁用所有包,然后只启用其中的一些包。

关于java - 为每个包启用断言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41936759/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com