| Author |
Switch Statement
|
Sridhar Padala
Greenhorn
Joined: Aug 03, 2007
Posts: 20
|
|
When I try to compile the below program class Switch1 { public static void main(String args[]) { final int a = 1; final int b; b= 2; int x = 1; switch (x) { case a: case b: }}} Error: Switch1.java:13: constant expression required case b: // ^ 1 error I want to know what is the difference between declarations mentioned below final int a = 1; and final int b; b= 2; Thanks in Advance :-)
|
 |
Raghavan Muthu
Ranch Hand
Joined: Apr 20, 2006
Posts: 3327
|
|
Hello Sridhar Padala , Welcome to Javaranch. Actually the switch statement expects its all 'case' expressions to be final and should get resolved at compile time. Thats the reason you get a compiler error.
|
Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
|
 |
Joanne Neal
Rancher
Joined: Aug 05, 2005
Posts: 3011
|
|
See Jim Yingst's post in this thread for further information. [ August 14, 2007: Message edited by: Joanne Neal ]
|
Joanne
|
 |
Raghavan Muthu
Ranch Hand
Joined: Apr 20, 2006
Posts: 3327
|
|
Yes, that link has the perfect and exact answer what you might look at. Thanks for pointing to the link Joanne Neal.
|
 |
Sridhar Padala
Greenhorn
Joined: Aug 03, 2007
Posts: 20
|
|
Thank You Very much Muthu......
|
 |
 |
|
|
subject: Switch Statement
|
|
|