Alex Rivera | Logout

Is it possible to create an empty Java enum type with methods?

Asked 2011-09-06T09:51:53.600
11

I can create an empty Java enum type, but when i want to add some methods : i get a "syntax error" (into Eclipse). I found no official documentation about this, so my question is : is it just impossible (so where is it clearly mentioned?) or is it just the compiler which is wrong ?

Edit
Report

1 Answer

1

Absoulely,

/**
 * @author The Elite Gentleman
 * @since 06 September 2011
 *
 */
public enum ExampleEnum {
    WHAT_ENUM
    ;

    public void doOperation() {

    }
}

Later:

ExampleEnum exEnum = ExampleEnum.WHAT_ENUM;
exEnum.doOperation();
answered 2011-09-06T09:55:55.027

Your Answer