How can I programmatically enable assert for particular classes, instead of specifying command line param \"-ea\"?
public class TestAssert {
private sta
Try
ClassLoader loader = getClass().getClassLoader();
setDefaultAssertionStatus(true);
or
ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true);
EDIT:
based on the comments
ClassLoader loader = ClassLoader.getSystemClassLoader();
loader.setDefaultAssertionStatus(true);
Class> c = loader.loadClass("MyClass");
MyClass myObj = (MyClass) c.newInstance();
public class MyClass {
private static final int foo[] = new int[]{4,5,67};
MyClass()
{
assert foo.length == 10;
}
}