/* Here's an alternative to the private null-argument constructor * in RussianDoll4.java. We could create the special * self-contained doll ZERO with a private function rather than * a private constructor. * * What's wrong with each of these signatures? * * public RussianDollCyclic() * // lets user do horrible stuff * private RussianDollCyclic() * // method, not constructor, so lowercase * private russianDollCyclic() * // where is return value? * private RussianDoll russianDollCyclic() * // needs to be static, so we can call it when * // initializing static ZERO (there's no instance!) * * Here's the right way to do the function: */ public static final RussianDoll ZERO = russianDollCyclic(); private RussianDoll(RussianDoll rd) { // our old constructor inner = rd; } private static RussianDoll russianDollCyclic() { RussianDoll rd = new RussianDoll(null); rd.inner = rd; return rd; // don't forget this! }