I have an Enum
in Java and I change it into enumerated annotations
like that:
public static final String PING = "ping";
public static final String PING_BACK = "ping.back";
public static final String REQUEST_MODE_NORMAL = "request_mode_normal";
public static final String ERROR_MESSAGE = "error_message";
@StringDef({PING, PING_BACK, REQUEST_MODE_NORMAL, ERROR_MESSAGE})
@Retention(RetentionPolicy.SOURCE)
public @interface Type {
}
@MessageCall.Type
private String mMessage;
Now I have another String
value are inputted by user and I want to pass this into mMesssage
field. That's a unknown value at compile time so I have to check this like that:
public MessageCall(String message) {
switch (message) {
case PING:
mMessage = PING;
break;
case PING_BACK:
mMessage = PING_BACK;
break;
case REQUEST_MODE_NORMAL:
mMessage = REQUEST_MODE_NORMAL;
break;
default:
mMessage = ERROR_MESSAGE;
}
}
I think that's so bad solution for me now and I wounder that "have any solution else to resolve my problem".
Thank you for your support.