I want to return from the static block.
Looks like the return and break statement don't work. Is there any alternative.
I know the bad workaround could be create a flag and check the flag to continue or not.
I understand that the initialisation blocks are not meant for doing computations but just for basic initialisation during class loading.
Delegate the code to a private static method:
static {
    initialize();
}
private static void initialize() {
    foo();
    if (someCondition) {
        return;
    }
    bar();
}
                        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