I came across the code below, and was wondering if each Tree instance would be referencing a different EMPTY object, or if it would reference the same object for all tree instances (only be instantiated once).
class Tree<T> {
public final Tree<T> EMPTY = new EmptyTree<T> ();
/** True iff THIS is the empty tree. */
public boolean isEmpty () { return false; }
private static class EmptyTree<T> extends Tree<T> {
/** The empty tree */
private EmptyTree () { }
public boolean isEmpty () { return true; }
}
...
}
My intuition was that it would have to be 'public static final....' for only one object to be initialized across the class for EMPTY.