You can now finally use a string in a switch statement, hurray (it's the little things that make me happy)! http://download.oracle.com/javase/7/docs/technotes/guides/la...
In a prev job, I saw this block of code -
-------
public int getDaysInMonth( String month ) {
if( month.equalsIgnoreCase("january")) return 31;
else if( month.equalsIgnoreCase("february")) return 28;
else if( month.equalsIgnoreCase("march")) return 31;
else if( month.equalsIgnoreCase("april")) return 30;
...
}-------
My eyes bled. I said folks, just map the month to an int M in range [1..12] and simply write 1 line of code
return 30+((M+Math.floor(M/8))%2;
( except for 2, which is 28 or 29 depending on a leap year)
I was overruled. "We are programmers, not mathematicians" was the response!!!
Now they'll happily use this string-switch to do
---------
switch( month.toLowerCase() ) {
case "january" return 31;
case "february" return 28;
case "march" return 31;
case "april" return 30;
... default : return -1;
}-------
which is an even nastier abomination :(