Taken from here, why is this syntax valid:
class X {
class Y {
Y(T a, Z b) {...}
}
public static void main(String... args) {
// why is this valid? the second new looks confusing to me
X<String>.Y<String> x1 = new X<String>().new Y<String>("",""); //ok
}
}
Since when has this syntax (new Foo().new Bar()) been valid?
Since Java 1.1, apparently (thanks @emory).
Class “Y” is a non-static, nested (inner) class of class “X”. As such, any instance of class “Y” must be constructed from an “outer” instance of class “X”.
See also this article which describes nested classes well: http://blogs.oracle.com/darcy/entry/nested_inner_member_and_top