Returning in a static class constructor
- by Martijn Courteaux
Hello,
This isn't valid code:
public class MyClass
{
private static boolean yesNo = false;
static
{
if (yesNo)
{
System.out.println("Yes");
return; // The return statement is the problem
}
System.exit(0);
}
}
This is a stupid example, but in a static class constructor we can't return;.
Why? Are there good reasons for this? Does someone know something more about this?
So the reason why I should do return is to end constructing there.
Thanks