0

I got following code and that gives me some grief:

public class CodePointBuffer {
    public enum Type {
            BYTE,
            CHAR,
            INT
    }
    private final Type type;

    private CodePointBuffer(Type type) {
        this.type = type;
    }

    public static CodePointBuffer withBytes() {
        return new CodePointBuffer(Type.BYTE);
    }
}

I wonder how Java can allow access to a non-static nested type (aka. inner type) from a static method. The inner type (here the enum Type) requires an instance of the outer class, which is not the case in this context. So, how is this acceptable?

Mike Lischke
  • 48,925
  • 16
  • 119
  • 181

0 Answers0