title: Is an enum constant-specific class body static or non-static?
body: <p>I have a enum type class:</p>
  
  <pre><code>public enum Operation {
      PLUS() {
          @Override
          double apply(double x, double y) {       
              // ERROR: Cannot make a static reference
              // to the non-static method printMe()...
              printMe(x);
              return x + y;
          }
      };
  
      private void printMe(double val) {
          System.out.println("val = " + val);
      }
  
      abstract double apply(double x, double y);
  }
  </code></pre>
  
  <p>As you see above, I have defined one <code>enum</code> type which has value <code>PLUS</code>. It contains a constant-specific body. In its body, I tried to call  <code>printMe(val);</code>, but I got the compilation error:</p>
  
  <blockquote>
    <p>Cannot make a static reference to the non-static method printMe().</p>
  </blockquote>
  
  <p>Why do I get this error? I mean I am overriding an abstract method in <code>PLUS</code> body. Why is it in <code>static</code> scope? How to get rid of it? </p>
  
  <p>I know adding a <code>static</code> keyword on <code>printMe(){...}</code> solves the problem, but I am interested to know if there is another way if I want to keep <code>printMe()</code> non-static?</p>
  
  <hr>
  
  <p>Another issue, quite similar as above one, but this time the error message sounds the other way around, i.e. <code>PLUS(){...}</code> has non-static context:</p>
  
  <pre><code>public enum Operation {
      PLUS() {
          // ERROR: the field "name" can not be declared static
          // in a non-static inner type.
          protected static String name = "someone";
  
          @Override
          double apply(double x, double y) {
              return x + y;
          }
      };
  
      abstract double apply(double x, double y);
  }
  </code></pre>
  
  <p>I try to declare a <code>PLUS</code>-specific <code>static</code> variable, but I end up with error:</p>
  
  <blockquote>
    <p>the field "name" can not be declared static in a non-static inner type.</p>
  </blockquote>
  
  <p>Why can I not define static constant inside <code>PLUS</code> if <code>PLUS</code> is an anonymous class? The two error messages sound contradictory to each other, as the 1st error message says <code>PLUS(){...}</code> has <strong>static</strong> context while the 2nd error message says <code>PLUS(){...}</code> has <strong>non-static</strong> context. I am even more confused now.</p>