Java specification says:
Static nested classes are accessed using the enclosing class name
Yet, I'm able to access and reference the static nested class WITHOUT specifying the enclosing class name:
Test.java (in some other package)
public static void main(String[] args) { //referencing the static class without the enclosing class name! Builder b = new Builder(); //ok! no need for "Response.Builder" } // also from a non-static method public void foo() { //referencing the static class without the enclosing class name! Builder b = new Builder(); //ok! no need for "Response.Builder" } What am I missing here? Does not this contradict the spec?
Response.java (the enclosing class) and Builder.java (the static nested class):
public class Response { public static class Builder { public Builder() { } public Response build() { // build Response instance } } }
importat the top.