This content has been marked as final.
Show 3 replies
-
1. Re: how to insert an 'assert' instruction ?
chiba Jun 8, 2005 5:32 AM (in response to nadz)If you don't need to turn on/off assertions, you can easily insert by
doing this:
insertAfter("if (expr) throw new AssertionError();")
This is equivalent to:
assert expr;
If you want to turn on/off by the -ea option, you have to also insert
the code for checking whether or not the assertion is effective
something like:
if (Foo.class.desiredAssertionStatus())
if (expr)
throw new AssertionError(); -
2. Re: how to insert an 'assert' instruction ?
nadz Jun 8, 2005 8:33 AM (in response to nadz)Thanks you very much !
-
3. Re: how to insert an 'assert' instruction ?
chiba Jun 8, 2005 10:19 AM (in response to nadz)One more thing.
Calling Foo.class.desiredAssertionStatus() would take time.
The bytecode generated by javac calls this method in a
static initializer and the result is cached in a private static
field.