Christ these are features we should be excited for? Give us proper lambdas. Give us pattern matching on types with extraction. Give us first class functions. Give us higher kinded generics so we can stop duplicating code. None of these things are impossible to do without breaking compatibility, so just do it already.
Popular languages with lambdas/closures/first class functions:
Ruby, Python, C#, Objective-C, Javascript, C++ 11
...
PHP
If you happen to find yourself being the personification of a programming language, and if you discover that PHP is a more advanced language than yourself then you have my permission to spend a night drinking heavily before hanging yourself from a lamp cord tied to a rafter in the garage.
But all of those things are accomplished using plain Java (I.e. a Function1<InputType, OutputType>) and classes with static methods for objects etc. It's not done at a bytecode level. You can do everything you can do in Scala... in Java, it's just hilariously verbose.
> There have been countless times when I wished I could
> have just used a String in a switch statement. When I
> hit this block when coding, I’m forced by Java to refactor
> my code to use a primitive datatype in my switch statement
I tend to use an enum instead, as it keeps the meaning clearer. For his example:
private static enum StringFields { ADDO_QUAYE, BOATENG_NICOLAS, DEFAULT }
try {
field = StringFields.valueOf(fullName.replace(' ', '_').toUpperCase());
} catch(IllegalArgumentException e) {
field = StringFields.valueOf("DEFAULT");
}
switch (field) {
case ADDO_QUAYE:
System.out.println("He is the SRC president");
break;
case BOATENG_NICOLAS:
System.out.println("He is the SU president");
break;
case default:
System.out.println("He is no body!");
break;
}
I would love to know what Google's plan is wrt to Java7 support for Android development. With the fairly minor changes at the byte code level it seems like it couldn't be too hard to support it, but I've seen / heard absolutely nothing to suggest Google will ever update. Perhaps they are too worried about Oracle booby-trapping it somehow, or they have other long term plans. But as far as I can tell right now, Google's plan is to stagnate on Java6 forever, which is sad.
Could have been nice, if they supported other types of matching. e.g. contains or regex. The vast majority of the time when I want to switch on a String I'm parsing a URL in a session filter into several categories or something like that.
As InclinedPlane said, Enums are more DRY and less error-prone. Even if you have to parse a String to an Enum, you only have to do it in one place (in the Enum definition), and then you only work with known objects. Also, if you want to refactor/auto replace, with an Enum object you are sure the value is correctly replaced everywhere (as the IDE knows to handle Enum), but if you want to replace a String you have to check all the occurrences of the string by hand, because some of them may be used for other purposes.