Monday 26 October 2015

Can be declare enum inside the interface?

It's perfectly legal to have an enum declared inside an interface.

In this situation the interface is just used as a namespace for the enum and nothing more. The interface is used normally wherever we use it.


public interface IService {
     public enum Status { // enum
           OK(200), INTERNAL_ERROR(500), KO(0);

           private int errorCode;

           private Status(int errorCode) {
                this.errorCode = errorCode;
           }

           public int getErrorCode(){
                return errorCode;
           }
     }
}

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...