Bug 31942 - Bug with Selection Statement switch()
Summary: Bug with Selection Statement switch()
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0.2   Edit
Hardware: PC Windows All
: P3 blocker (vote)
Target Milestone: 2.1 RC1   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: core
Depends on:
Blocks:
 
Reported: 2003-02-15 11:11 EST by Pedro da Silva Garcia CLA
Modified: 2003-02-17 13:09 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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;}
    }
}
}