James MV
James MV

Reputation: 8717

Working with Enum?

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?

Upvotes: 1

Views: 512

Answers (3)

Jordan Bentley
Jordan Bentley

Reputation: 1309

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

Upvotes: 0

MByD
MByD

Reputation: 137282

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);

Upvotes: 4

Jigar Joshi
Jigar Joshi

Reputation: 240860

Try this

checkEnum(myEnum.Value1);

Upvotes: 1

Related Questions