All code is in Java.
public class TestLocal
{
public static void main(String [] args)
{
int x;
if (args[0] != null)
{ // assume you know this will
// always be true
x = 7; // statement will run
}
int y = x; // the compiler will choke here
}
}
So, my Question is why does the compiler choke here? Does it bypass the if statement (This look quite horrible...) If I initialize x outside the if statement block then the compiler does not complain, as in this code:
public class TestLocal
{
public static void main(String [] args)
{
int x;
x = 7; // compiler is happy now..:)
if (args[0] != null)
{ // assume you know this will
// always be true
// statement will run
}
int y = x; // the compiler not complain here now.
}
}
Why such a horrible behavior from the compiler?