Feedback and comments on ARM proposal - resend

Neal Gafter neal at gafter.com
Tue Mar 17 22:43:40 PDT 2009


On Tue, Mar 17, 2009 at 9:50 PM, Howard Lovatt <howard.lovatt at iee.org> wrote:
>> Agreed, though there is one context in which it is possible to jump
>> into the scope of a local variable declaration without "executing" the
>> declaration: the switch statement.
>
> I thought this was only in C/C++ and Java had plugged this hole - I
> guess I am wrong - do you have an example.

Below, in the form of a puzzler.  What does the program print?  If you
remove "final", does the answer change?

import java.io.*;
class T {
    public static void main(String[] args) {
	switch (args.length) {
	case 0:
	    final int i = 0; // a constant variable
	    break;
	case 1:
	    i = 1; // i is not definitely assigned here, so we assign to it
	    System.out.println(i); // i is constant, so prints 0? 1?
	    break;
	}
    }
}



More information about the coin-dev mailing list