The main idea of IntDef annotation is to use set of int constants like an enum, but without enum. In this case you have to declare all constants manually.

@IntDef({Status.IDLE, Status.PROCESSING, Status.DONE, Status.CANCELLED})
@Retention(RetentionPolicy.SOURCE)
@interface Status {
    int IDLE = 0;
    int PROCESSING = 1;
    int DONE = 2;
    int CANCELLED = 3;
}

You can see detailed example here.


Well, you can't quite do it that way. AppEnums.SERVICE_ERROR will never return int; it will return AppEnums.SERVICE_ERROR. That's the point of enumerated types.

What I can suggest is this:

public static class AppEnums {
    public static final int CONNECTION_ERROR = 0;
    public static final int SERVICE_ERROR = 1;
}

@IntDef({AppEnums.CONNECTION_ERROR,AppEnums.SERVICE_ERROR})
    public @interface ServiceErrors {
}

Copied from Yazazzello's comment below:

IntDef - new Enums for Android development. Enums often require more than twice as much memory as static constants. You should strictly avoid using enums on Android. so IntDef where designed to replace Enums, you cannot use Enum in IntDef declarations