What’s the Java equivalent of C#’s:
enum Foo
{
Bar = 0,
Baz = 1,
Fii = 10,
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you want attributes for your
enumyou need to define it like this:You’d use it like this:
The thing to realise is that
enumis just a shortcut for creating a class, so you can add whatever attributes and methods you want to the class.If you don’t want to define any methods on your
enumyou could change the scope of the member variables and make thempublic, but that’s not what they do in the example on the Sun website.