-
June 8th, 2010, 09:28 PM
#1
Enum: how to call an enum constant's own method?
Hi,
I'm a Java and Codeguru newbie, so please don't be too harsh.
I'm currently having this issue with enum: I'm creating an enum type that has several enum constants, one of which has its own method like this:
public enum EnumType {
ENUMCONSTANT1,
ENUMCONSTANT2,
ENUMCONSTANT3 { void constant3sOwnMethod() { } }
// enum type's constructor and other methods
...
}
My question is: how do I call constant3sOwnMethod() ?
If I don't use this method anywhere it compiles fine. But if I add a line to call the method such as this:
EnumType.ENUMCONSTANT3.constant3sOwnMethod();
it won't compile, but instead shows error message: "cannot find method constant3sOwnMethod()"
Please help!!!
P.S. Sorry I'm still trying to figure out how to post indented source code.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|