I have an Enum in .Net. How can I rewrite this Enum in java?
Here is the Enum:
public enum AdCategoryType : short
{
    ForSale = 1,
    ForBuy = 2,
    ForRent = 8,
    WantingForRent = 16,
    WorkIsWanted = 32, 
    WorkIsGiven = 64
}
I have an Enum in .Net. How can I rewrite this Enum in java?
Here is the Enum:
public enum AdCategoryType : short
{
    ForSale = 1,
    ForBuy = 2,
    ForRent = 8,
    WantingForRent = 16,
    WorkIsWanted = 32, 
    WorkIsGiven = 64
}
 
    
     
    
    This gets you the enum:
public enum AdCategoryType {
    ForSale(1),
    ForBuy(2),
    ForRent(4),
    WantingForRent(8),
    WorkIsWanted(16),
    WorkIsGiven(32);
    private final int value;
    AdCategoryType(int value) {
        this.value = value;
    }
    public int getValue() {
        return this.value;
    }
}
 
    
    This will work:
public enum AdCategoryType {
    ForSale/*           */ (1 << 0), //
    ForBuy/*            */ (1 << 1), //
    ForRent/*           */ (1 << 2), //
    WantingForRent/*    */ (1 << 3), //
    WorkIsWanted/*      */ (1 << 4), //
    WorkIsGiven/*       */ (1 << 5);
    private final int value;
    private AdCategoryType(int value) {
        this.value = value;
    }
    public int getValue() {
        return this.value;
    }
};
To get the value of ForBuy use AdCategoryType.ForBuy.getValue().
 
    
    public enum Foo
{
   Bar(1),
   Baz(45);
   private short myValue;
   private short value()
   {
     return myValue;
   }
   public Foo(short val)
   {
      myValue = val;
   }
}
