Example: This WILL NOT WORK
NonEmptyTree<String, Integer> t2 = new NonEmptyTree<String, Integer>("Mary", 20, EmptyTree.getInstance(), EmptyTree.getInstance());
Instead you need to:
EmptyTree<String, Integer> empty = EmptyTree.getInstance();
NonEmptyTree<String, Integer> t2 = new NonEmptyTree<String, Integer>("Mary", 20, empty, empty);
Why??
Because of some backwards compatibility issues, javac only does type inference for static
methods when it is used to initialize a variable.