How can I reference my Java Enum without specifying its type

Actually, you can do a static import of a nested enum. The code below compiles fine:

package mypackage;

import static mypackage.Test.MyEnum.*;

public class Test
{
    enum MyEnum{E1, E2};

    public static void aTestMethod() {
        Test2(E1);  
    }

    public static void Test2(MyEnum e) {}
}

Leave a Comment