// Demonstrating how JDK 1.4's $switch$ makes // some of the old notes invalid! (They used older JDK.) interface Test { int X = 4; } class Blah implements Test { } public class SwitchTest { public static void main(String[] args) { // X is public static final, so no problem here: System.out.println("Test 1: "+Blah.X); System.out.println("Test 2: "+Test.X); // No problem here, either: Blah b = new Blah(); System.out.println("Test 3: "+b.X); // Case labels require constants and *constant expressions* // (no variables!), so the following won't work! int i = 4; switch(i) { case b.X: // need to fix with Test.X System.out.println("It's a match!"); break; default: System.out.println("It's crap!"); } // Don't believe me? Try the following: int j = 5; int k = j; switch(j) { case k: // need to fix with 5! System.out.println("It's a match!"); break; default: System.out.println("It's crap!"); } } }