Why there cannot be multiple exit points from a static initializer? Does Java Language specification state so?
When trying to compile code as:
class HelloWorldApp {
static {
if(1 > 2)
return;
System.out.println("static");
}
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
Compiler prints out an error: return outside method
Java disassembly with javap shows that static is a void method, so would it be possible, theoretically, to create a bytecode that would have multiple 'returns'?
The JLS states that a return statement within a static initializer is illegal here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With