Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about local variables in switch  RSS feed

 
Arsineh Keshishian
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

When running this code:

int n = 4
final int x = 3;
final int y = 4;


I'M getting a compiler error because of j using in case y.
The compiler complains that "j may have not been initialized yet". But I can not reinitialize j either because of "duplicate local variable j".
So the only way is to make j final in case x: final int j = 0;

Why does j has to be final?

Thank you
Arsineh
 
Ravikanth kolli
Ranch Hand
Posts: 179
Chrome Eclipse IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do you have a global variable "j"?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!