1

Have a bit of trouble working with enums, how do you pass a method to an enum? This is a basic overview of the code:

public enum myEnum{
            UNDEFINED, Value1, Value2
}

checkEnum(myEnum passedValue){
//do check stuff here
}

No I want to pass "Value1" to checkEnum but if I just say:

checkEnum(Value1);

Eclipse won't let me, in what format does my variable have to be to pass it to my method checkEnum?

3 Answers 3

4

It should be:

checkEnum(myEnum.Value1);

Also, the convention is to start Enums and Class names in upper case letter. e.g.

checkEnum(MyEnum.Value1);
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, what if I'm making the call from another class?
The same. if you are doing it from a separate package though, you will need to import the Enum.
1

Try this

checkEnum(myEnum.Value1);

Comments

0

It needs to be qualified, checkEnum(myEnum.Value1); should work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.