How to allow static initializer on a inner class like this:
public class MyClass {
    public class InnerClass {
        static {
            // do something
        }
        public bar(){
            // do something
        }
    }
    // method stuff
    public void foo() {
        // do something
    }
} 
                From JLS 8.1.3 Inner Classes and Enclosing Instances:
Inner classes may not declare static initializers (§8.7) or member interfaces.
What you may want is a nested class:
public static class InnerClass { // note "static"
                        You need to define the InnerClass class as static. But, thereafter, it won't be a regular inner class.
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