Hi,
I want to ask a basic Question regarding assertion.
usually assert syntax for java1.5 will be
assert (booleanvalue);
assert (booleanvalue): expression;
in the 2nd syntax,I want to know that if the booleanvalue is false,whether the expression gets evaluated?
ie,once the boolean value is false,we get assertionerror(run with -ea).In that case,i want to know whether the expression will be evaluated or not.
I want to know one more thing,how to compile a program with assertion enabled both in commandprompt and using eclipse.
public class Assertest{
static int i =10;
public static void main(
String[] args){
i= i*2;
try{
System.out.println(isValid());
assert isValid()
i=i/4);
System.out.println("inside i"+i);
}
catch(AssertionError e){
System.out.println("i=" + i);
}
}
public static boolean isValid(){
i=i*2;
return false;
}
}
when i compiled the program,i got the answer as i=20.can anyone explain this.i thought the answer will be i=40.
I want to know the answer for the above Question with assertion enabled and assertion disabled.Please explain the difference when assertion enabled and assertion disabled.It is confusing for me.
Advance thanks to the group for the effort put in.