Code Obfuscation: Anonymous Inner Class Death

Java, like most other modern languages, will let you get away with some really ugly code. Inspired by my recent gaze into GWT generated JavaScript, I decided to crank out this little gem. I’ve pretty formatted it here because it doesn’t need any assistance to confuse from lack of white space. See if you can figure out what it does and, more importantly, how it does it.

new Object() {
    public void eval(int i) {
      if (new Object() {
            public boolean eval(int i) {
              return i == new Object() {
                  public int getSomeNumber() {
                    return 1000;
                  }
                }.getSomeNumber();
            }
          }.eval(i))
        return;
      System.out.println(String.format("%c", i));
      this.eval(new Object() {
            public int next(int i) {
              return i + new Object() {
                  public int leap() {
                    return 1;
                  }
                }.leap();
            }
          }.next(i));
    }
  }.eval(0);

Take a moment and really drink this in. Its fairly simple to obfuscate just about any simple algorithm using this terrible approach. I don’t even want to think about what this is doing to the JVM’s memory, let alone mine.