JEP-455: Primitive types in patterns, instanceof and switch
openjdk.org
openjdk.org
Switch statements are rarely used in my experience in preference to array indexing/hashmap/properties or just if/else.
Now Java devs need to remember switches can have guards, do auto boxing, and can do work which is duplicating getters/setters or just general purpose validation by annotation (JSR 303 if memory serves).
This is a good example of Java becoming bloated imho. Something like JSRs such as streams were useful syntactic sugar for functional and threaded programming, but something like this adds no tangible benefits over what is already in the language.
Little changes here and there are eroding a core value of the language imho, and those devs choose different easier languages to start with. Without new blood languages die.
I am surprised Brian Goetz endorsed this (I've got his older Java book Concurrency in Practice) so can only assume there's a larger picture I don't see.
As stated, I believe Java is "jumping the shark" when it should be making breaking changes (not just huge deprecations). Also I'm not sure why my parent comment has been downvoted for a unpopular view, it's a genuine concern and why I now prefer to use other simpler languages instead when not in a work context.
* dirty meaning quick and/or checking internal state instead of output
Whenever I do something in a neat, elegant match-statement in Rust, going back to a language which lacks these is painful. This isn't bloat, it's keeping up with the times.
It's should go the way of goto, which also happens coincidentally to be a way of using labels (fun off topic fact goto is a keyword in Java as pre 1.0 it was represented in bytecode).
Nb arguing that it also prevents excess code is somewhat moot, the Java community for better or worse favours anemic models full of empty setters and getters, that is probably a more important area to address than just introduce a new record type to avoid these.
Pattern matching has finally made it out of ML land and getting increasingly implemented in mainstream languages. I'm not sure if Rust is the main driver here, but I'm glad to see it.
private String[] alphabetIndex = new String["A", "B"...];
public String getLetterAtIndex(int index1Based) {
return alphabetIndex[index1Based-1];
}