Ditch the String representation, and do a real enum.
public enum DataType {
STRING,
BOOLEAN,
INTEGER;
}
That way you avoid ever having to do string comparison of the previous String dataType variable to determine if it is in the enum. As an aside, it also makes it impossible to assign a non-valid value to the member variable dataType and since enums are guaranteed to be singletons within the class loader, it also saves on memory footprint.
It's worth the effort to change your code to use enums. However, assuming that you can't, you can at least change the annotation to use enums.
@ValidateString(DataType.STRING) String dataType;
and that way your ValidateString annotation at least gets to benefit from enums, even if the rest of the code doesn't.
Now on the extremely rare chance that you can't use an enumeration at all, you can set static public integers, which map each accepted value.
public class DataType {
public static final int STRING = 1;
public static final int BOOLEAN = 2;
...
}
However, if you use a String for the annotation parameter, we don't have a type checking system which extends into the type to specify that only particular values are allowed. In other words, Java lacks the ability to do something like this:
public int<values=[1,3,5,7..9]> oddInt;
which would throw an error if you attempted to assign
oddInt = 4;
Why is this important? Because if it doesn't apply to regular Java, then it cannot apply to the enumeration which is implemented in regular Java classes.