Bug 31942

Summary: Bug with Selection Statement switch()
Product: [Eclipse Project] JDT Reporter: Pedro da Silva Garcia <pedro00355>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: RESOLVED WONTFIX QA Contact:
Severity: blocker    
Priority: P3 Keywords: core
Version: 2.0.2   
Target Milestone: 2.1 RC1   
Hardware: PC   
OS: Windows All   
Whiteboard:

Description Pedro da Silva Garcia CLA 2003-02-15 11:11:48 EST
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.
Comment 1 DJ Houghton CLA 2003-02-16 10:22:03 EST
This works ok for me.
Can you give a step-by-step example to reproduce the problem?
Thanks.
Comment 2 Rafael Chaves CLA 2003-02-16 19:57:53 EST
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.
Comment 3 Philipe Mulet CLA 2003-02-17 05:12:25 EST
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.
Comment 4 DJ Houghton CLA 2003-02-17 13:09:02 EST
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;}
    }
}
}