title: Static context in enum definition
body: <p>The syntax sugar provided by Java's <code>enum</code> facility can sometimes be a little confusing. Consider this example, which does not compile:</p>
  
  <pre><code>public enum TestEnum {
  
      FOO("foo") {
          public void foo() {
              helper();  // &lt;- compiler error
          }
      };
  
      String name;
      TestEnum(String name) {
          this.name = name;
      }
  
      public abstract void foo();
  
      private void helper(){
          // do stuff (using this.name, so must not be static)
      }
  }
  </code></pre>
  
  <p>Can anyone explain why the compiler says </p>
  
  <blockquote>
    <p>Non-static method 'helper()' cannot be referenced from a static context</p>
  </blockquote>
  
  <p>How exactly is this context static?</p>
  
  <p>You can make this compile by changing the call to <strong><code>this.</code></strong><code>helper()</code> (here is one confusing point: if we really are in a "static context" like the compiler suggests, how can "<code>this</code>" work?) or by increasing the visibility of <code>helper()</code> to default level. Which would you prefer? Also, feel free to suggest a better question title :-)</p>
  
  <p><strong>Edit</strong>: I found <a href="http://74.125.77.132/search?q=cache:yTkD6C3gZTEJ:x86.sun.com/thread.jspa%3FmessageID%3D3780246" rel="noreferrer">some discussion about this</a> - but no real answers. My colleague thinks the fact that that <code>this.helper()</code> works is actually a compiler bug. And indeed with newer Java versions it seems <em>not</em> to work (although <code>super.helper()</code> does): "cannot find symbol helper()". (Although there's something odd going on: after trying with different Java versions I can't get <code>this.helper()</code> to compile again with any of them...)</p>