Variable scoping in Kaffe and JDK

Moses DeJong dejong at cs.umn.edu
Mon Mar 1 13:49:17 PST 1999


That is a bug in the pizza compiler that is used by kaffe.

Mo DeJong
dejong at cs.umn.edu

On Mon, 1 Mar 1999 jbl at cordelia.res.cmu.edu wrote:

> 
> 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