代码之家  ›  专栏  ›  技术社区  ›  NullVoxPopuli

Java:这个数据结构叫什么?

  •  2
  • NullVoxPopuli  · 技术社区  · 15 年前

    我想要一些像 MOTIVE { GET_PLAYER, GET_FLAG } .

    在我的目标中,我想要

    this.motive = MOTIVE.GET_PLAYER
    

    我该怎么做?

    3 回复  |  直到 15 年前
        1
  •  10
  •   Romain Linsolas    15 年前
        2
  •  2
  •   extraneon    15 年前

    /**
     * Don't use caps for a "class" name :)
     */
    public enum Motive {
      GET_PLAYER,
      GET_FLAG;
    
    }
    

    /**
     * Don't use caps for a "class" name :)
     */
    public enum Motive {
      GET_PLAYER("Assessination Quest"),
      GET_FLAG("Capture the Flag PvP");
    
      private Motive(final String desc) {
         this.description = desc;
      }
    
      public String getDescription() {
        return description;
      }
    
      private final String description;
    }
    

    public final class MyClass {
        private Motive motive;
    
        public MyClass(final Motive motive) {
            this.motive = motive;
        }  
    }
    

        3
  •  1
  •   Jigar Joshi    15 年前