Question

In a legacy code of an Android device I've found following piece of art (definition of interface):

public interface ErrorIdentifiers {
    public static final int SUCCESS = 0;
    public static final int NOT_AVAILABLE = 1;
    public static final int GENERIC_FAILURE = 2;
    public static final int REQUEST_NOT_SUPPORTED = 3;
    public static final int REQUEST_CANCELLED = 4;
    public static final int INVALID_RESPONSE = 5;
    public static final int LIST_DOWNLOAD_NOT_FINISHED = 6;
    public static final int TIMEOUT_ERROR = 7;

    public static final int DIR_FOUND = 0;
    public static final int DIR_NOT_FOUND = 1;
    public static final int DIR_INVALID_PROVIDER = 2;
    public static final int DIR_NO_DATA_CONNECTION = 3;
    public static final int DIR_OTHER_ERROR = 4; 

    // ... and many many more
}

The it's then used like this:

resultcode = ErrorIdentifiers.SUCCESS;

Is it bad to use interface in that way? How to do error identifiers in a proper way?

Was it helpful?

Solution

Nothing wrong when using an interface like this.

However, there's some redundancy in the code. public static final could be removed as redundant, as per JLS 9.3:

Every field declaration in the body of an interface is implicitly public, static, and final. It is permitted to redundantly specify any or all of these modifiers for such fields.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top