class A {
void m1(int i) {
int j = i % 3;
switch (j) {
case 0: System.out.print("0"); break;
case 1: System.out.print("1"); break;
default:
assert j == 2;
System.out.print(j);
}}
public static void main (
String[] args) {
A a = new A();
for (int i=5; i >= -1; i--) {a.m1(i);}
}}
Assertion disabled,
java A would result in 210210-1
Why does Assertion enabled?
java -ea A would result in 210210 and AssertionError.
During the last iteration of for loop which assertion enabled, value of i is -1, method m1 is called with value -1. In switch construct shouldn't default get's executed printing value of j which is -1 (giving output similar to assertion disabled output (210210-1) followed by AssertionError)??
Please help.
Thank you in anticipation.
Raghav