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().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With