Returning in a static class constructor
Posted
by Martijn Courteaux
on Stack Overflow
See other posts from Stack Overflow
or by Martijn Courteaux
Published on 2010-04-09T11:53:29Z
Indexed on
2010/04/09
12:03 UTC
Read the original article
Hit count: 323
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
© Stack Overflow or respective owner