February 24, 2012

How to put twenty clowns in a Volkswagen

Context: here.
public class You {
      private static Volkswagen vw;

      private static final class Popo extends Clown {
            private static int clowns = 0;
            private boolean unpacked = false;

            public Popo() { clowns++; }

            @Override
            public int hashCode() {
                  if (!unpacked && clowns < 20) {
                        unpacked = true;
                        vw.add(new Popo());
                  }
                  return super.hashCode();
            }
      }

      public static void main(String args[]) {
            vw = new Volkswagen();
            vw.add(new Popo());
            vw.done();
      }
}
Yes, I know, this can be made shorter. Don't really care. :-)

No comments: