Possible Duplicate:
Switch Statement with Strings in Java
Im using the following code and I wonder if there is a way to do it with switch ,
the reason that I don’t use it as default since type name is type string.(I know that this option is supported in 1.7 version but I need to use 1.6)
There is a way to overcome this problem ?
public static SwitchInputType<?> switchInput(String typeName) {
if (typeName.equals("Binary")) {
return new SwitchInputType<Byte>(new Byte("23ABFF"));
}
else if (typeName.equals("Decimal")) {
return new SwitchInputType<BigDecimal>(new BigDecimal("A"));
}
else if (typeName.equals("Boolean")) {
return new SwitchInputType<Boolean>(new Boolean("true"));
As explained in other answers, you can’t use switch statement with strings if you’re working with Java 1.6.
The best thing to do is to use an enumerator instead of string values:
where:
UPDATE:
In your
Fieldclass add anInputType fieldTypeproperty. Then inside the loop: