Variable scoping in Kaffe and JDK
jbl at cordelia.res.cmu.edu
jbl at cordelia.res.cmu.edu
Mon Mar 1 00:11:40 PST 1999
I've got a Kaffe and Java language question here.
If I declare a variable in one case block of a switch
statement, does Java let me use the same variable name
in another block of the same switch statement? Can I
do this:
switch(vegetable) {
default:
int fruit = 1;
.
.
.
break;
case 1:
int fruit = 2;
.
.
.
break;
}
Kaffe does not complain about this, however Sun's javac
compiler does complain with a message that says "fruit"
is already declared in the _method_. Well, "fruit" in
my code was not declared anywhere else in the function
except in with the case blocks within the switch block.
So, which way is the real way? I'm curious to know since,
I lost twenty points on my Data Structures homework. :)
--
John B. Lee, Undergraduate
Social and Decision Science; Carnegie Mellon University
jbl at andrew.cmu.edu
More information about the kaffe
mailing list