java – 启用每个包的断言
作者:互联网
是否可以在每个包中启用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 classFor
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,assertions 来源: https://codeday.me/bug/20190516/1114375.html