Skip to content

Instantly share code, notes, and snippets.

@SanthoshBabuMR
Created April 14, 2020 02:17
Show Gist options
  • Save SanthoshBabuMR/71f5952e7763e45a5042e00c3ffb5683 to your computer and use it in GitHub Desktop.
Save SanthoshBabuMR/71f5952e7763e45a5042e00c3ffb5683 to your computer and use it in GitHub Desktop.
// enum is private class with static final members
enum PersonType {
Men,
Women,
Transgender
}
class Person {
Person(String name, PersonType gender) {
this.name = name;
this.gender = gender;
}
String name;
PersonType gender;
}
public class Main {
public static void main(String[] args) {
Person person = new Person("foo", PersonType.Men);
System.out.println(String.format("person %s gender: ", person.name));
System.out.println(person.gender);
System.out.println("\n");
System.out.println("Looping all values in enum");
// get all values in enum
PersonType[] values = PersonType.values();
for(PersonType personType: PersonType.values()) {
System.out.println(personType);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment