Community
Participate
Working Groups
When you decide to use a switch statement with variables that are not final. The IDE presents you an error saying that the expression needs to be a constant.
This works ok for me. Can you give a step-by-step example to reproduce the problem? Thanks.
If you mean the expressions that appear in each case statement, they *must* be literals or final variables of int type, and that is not a IDE bug, it is a Java language requirement.
Closing, please reopen if you have steps which reproduce an actual bug (e.g. comparing to other compilers behavior). Also, then please indicate which build number you are using.
In the future please append your comments directly to bug reports and do not send them by email. Thanks. Comment from the originator: ----------- public class TesteSwitch { public int a = 0, b = 5; /** * Metodo para teste do erro com o switch. */ public void teste(int key){ switch (key) { case a :{// Error is reported here because of the variable a System.out.println("Teste A"); break; } case b :{// Error is reported here because of the variable b System.out.println("Teste B"); break; } default :{ System.out.println("Teste \"default\""); break;} } } }