title: How to get the enum type by its attribute?
body: <p>I have written an enum class and I want to either get the attribute by type or get the type by attribute, but it seems impossible.</p>
  
  <pre><code>public enum AreaCode {
      area1(7927),
      area2(7928),
      area3(7929);
  
      private final int ac;
  
      AreaCode(int ac) {
          this.ac = ac;
      }
  
      int areaCode(){
          return ac;
      }
  
      AreaCode area(int n) {
          switch (n) {
              case 7927: return AreaCode.area1;
              case 7928: return AreaCode.area2;
              case 7929: return AreaCode.area3;
          }
      }
  }
  </code></pre>
  
  <p>The code above will not compile. How to make <code>area(int n)</code> work?</p>