enum implementation inside interface - Java
It's perfectly legal to have an enum
declared inside an interface
. In your situation the interface is just used as a namespace for the enum and nothing more. The interface is used normally wherever you use it.
Example for the Above Things are listed below :
public interface Currency { enum CurrencyType { RUPEE, DOLLAR, POUND } public void setCurrencyType(Currency.CurrencyType currencyVal);}public class Test { Currency.CurrencyType currencyTypeVal = null; private void doStuff() { setCurrencyType(Currency.CurrencyType.RUPEE); System.out.println("displaying: " + getCurrencyType().toString()); } public Currency.CurrencyType getCurrencyType() { return currencyTypeVal; } public void setCurrencyType(Currency.CurrencyType currencyTypeValue) { currencyTypeVal = currencyTypeValue; } public static void main(String[] args) { Test test = new Test(); test.doStuff(); }}
In short, yes, this is okay.
The interface does not contain any method bodies; instead, it contains what you refer to as "empty bodies" and more commonly known as method signatures.
It does not matter that the enum
is inside the interface.