There are several cases when I want to switch over a String input. I decided for implementing something like:
public Object doStuff(String param) {
switch (param.hashCode()) {
case 1234546:
break;
case -18754956:
break;
default:
whatever();
}
}
It works as intended, but there is this feeling that something can go awry.
What are the possible pitfalls of using that implementation? I am bound to use java 1.5 or 1.6 because corporate dictates so (therefore I cannot upgrade to 1.7 or later).
Is there some better implementation of a switch over Strings other than a monstruous chain of if-then-else
(for the purpose of this question, lets assume I cannot do if-then-else over every possible String value of the input)?
related: What is the benefit of switching on Strings in Java 7? but I am asking pre-1.7