Pass ENUM Method Parameter Java

Pass ENUM Method Parameter Java

Here you will see how to create Enum and pass as method parameter in java class. Later we will load method with Enum and fetch its value:

  • EnumTest.java:
public enum EnumTest {
	
    NotAffirmed("Not Affirmed", 0),
    NotEligible("Not Eligible", 1),
    Affirmed("", 3),
    Rejected("", 4),
    Withdrawn("", 5);

    private final int value;
    private final String description;

    EnumTest(String description, int value) {
        this.description = description;
        this.value = value;
    }

    public int  getValue() {
        return value;
    }

    public String getDescription() {
        return description;
    }

}
  • ClassTest.java:
public class ClassTest{
	
	private EnumTest enumTest;

	public static void main(String[] args) {
		
		ClassTest classTest = new ClassTest();
		
		classTest.setValue(EnumTest.NotEligible);
		System.out.println(classTest.getValue().getValue());

	}

	public EnumTest getValue() {
		return enumTest;
	}

	public void setValue(EnumTest enumTest) {
		this.enumTest = enumTest;
		
	}

}

 

Reference:

Leave a Reply

Your email address will not be published. Required fields are marked *