Compiler Error J0092

Constant expression expected

The compiler detected an expression that used a non-constant value when a constant value was required. This error usually occurs when a variable is used in a case statement. Check the expression to be sure that a constant value is being used and compile again.

The following example illustrates this error:

public class Simple{
   int var1 = 10;
   int var2 = 20;
   public void method1(){
      switch(var1){
        case var2:
        //error: cannot use variable with case
      }
   }
}