Use Enum-value without using Enum-classname

class, enums, inheritance, java

Solution

You can use a static import:

import static com.yourpackage.StateSupport.State.NEW;
import static com.yourpackage.StateSupport.State.UNCHANGED;
import static com.yourpackage.StateSupport.State.UPDATED;

or in short (discouraged):

import static com.yourpackage.StateSupport.State.*;

Problem

I use a static enum in an interface and want to use it in an extending class. I have following interfaces: ``` public interface StateSupport { public static enum State { NEW, UNCHANGED, UPDATED; } } ``` and ``` public interface Support extends StateSupport { public void do(Context arg0); } ``` and finally a class ``` public class MyClassUtil implements Support { public void do(Context arg0){ MyClass obj = new MyClass(NEW); } ``` } The point is that I dont want to write "State.NEW", just "NEW" :-) So how can it do that without using the enum name. Is there a way at all?

Original source