Variable scoping in Kaffe and JDK

jbl at jbl at
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) {

      int fruit = 1;

   case 1:
      int fruit = 2;

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

More information about the kaffe mailing list