Project Coin on OpenJDK is soliciting ideas for small language changes for Java 7. The ideas so far appear to suggest features from C#, which is a superior language IMHO. In principle, I hate the idea of baking in cosmetic changes to a language. Scheme and Lisp macros are a profoundly better solution to syntactic issues, but mainstream programmers will never grok it. So Java has no choice but to add more stuff. Therefore, I think the switch statement is seriously underutilized in C-like languages. One idea is to add support for a limited degree of object pattern matching. Think of it as a painfully limited version of the case expression in many functional languages.
The switch in Java currently only allows a few primitive types. Change it so now you can have switch(objectType). Allow the case arms to support a boolean expression. To simplify things, allow access to object fields like this: “.field”. So the new switch would look like this:
A simpler idea is to stick with the regular switch statement, but support multiple switch variables. Right now, you can only do “switch (oneItem)”. Instead, you could allow “switch (oneItem, twoItem)” and more. In the case arms, right now they allow “case constant:”. Instead, this can be extended to allow “case constant1, constant2” and more. Obviously, each constant is matched with the switch variable in the same position. If there are too many constants, that’s a syntax error. If there are fewer constants, then ignore the remaining variables. Here’s an example:
Finally, the absolute simplest extension to the existing switch statement is to allow case ranges. This is already implemented in Visual Basic.NET with their Select Case statement. You say “Case 1 to 10” to match that range. Lots of languages support this. This feature won’t change the world, but it does make switch a bit more useful.