I have many if statements and I want to avoid them.
I tried with HashMap, but it did not work with datatypes. Please see the code below that I have. This is just the first if statements but I have more...
if (field.equals(DataTypes.IntegerType)) {
columns[i] = Integer.valueOf(s);
} else if (field.equals(DataTypes.LongType)) {
columns[i] = Long.valueOf(s);
} else if (field.equals(DataTypes.DoubleType)) {
columns[i] = Double.valueOf(s);
} else if (field.equals(DataTypes.FloatType)) {
columns[i] = Float.valueOf(s);
} else if (field.equals(DataTypes.StringType)) {
columns[i] = s;
} else if (field.equals(DataTypes.BinaryType)) {
columns[i] = Binary.fromString(s);
Can I somehow avoid so many else if statements?
Aucun commentaire:
Enregistrer un commentaire