| Author |
assertion
|
Maciek Zywno
Greenhorn
Joined: Jul 29, 2003
Posts: 2
|
|
hello I tried the following piece of code : public class AssertTest { public void methodA( int i ){ assert i >= 0 : methodB(); System.out.println( i ); } public int methodB(){ System.out.println( "The value must be nonnegative" ); return 1; } public static void main(String[] args) { AssertTest test = new AssertTest(); test.methodA( -10 ); } } As I execute it only "-10" is printed and no print from methodB(). I wonder why methodB() is not invoked. Sun's docs say that in assert Expression1 : Expression2 ; expression2 cannot be the invocation of a method that is declared void. In "my" case methodB() is not of a void type, so why it is not executed? If it is not executed how the expression2 is evaluated? what am I missing? thanks
|
 |
Alton Hernandez
Ranch Hand
Joined: May 30, 2003
Posts: 443
|
|
You must run it with assertion flag on: java -ea AssertTest
|
 |
 |
|
|
subject: assertion
|
|
|