I have a method that accepts only a String.
public void setVerticalAlignment(String align) {
...
gd.verticalAlignment = align; // accepts only
If you use Java 7 you can always use switch
on Strings:
switch (align) {
case "SWT.TOP":
gd.verticalAlignment = SWT.TOP;
/* etc */
}
Being honest I would avoid using strings like "STW.TOP"
. If I really had to store alignment state in the other way than just int
I would use enums which might be used in switch
in older versions of Java.