4 ms·
JEP-455: Primitive types in patterns, instanceof and switch
- dbacar 2y ago[flagged]
- CoastalCoder 2y agoThat fact alone makes me wonder what the bigger story is. E.g.: Are the pros/cons considerations very close to a tie? Is this change a no-brainer, implying that something about the Java is really slow to improve the language?
- PaulHoule 2y agoThey're just very careful.
- kaba0 2y agoJava previously didn’t have pattern matching, and now re-uses an older syntax to have that. There is nothing “slow”, java was never meant to be at the forefront of language design (it’s a blue-collar language). Even then, it is not at all behind compared to the other mainstream languages with this feature - most of them don’t have pattern matching at all.
- deleted 2y ago[deleted]
- deleted 2y ago[deleted]
- SillyUsername 2y agoThis actually looks like adding complexity. 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.
- high_na_euv 2y agoArray as replacement for switch? Maybe for simple cases
- SillyUsername 2y agoNot as a general case, but something like (not withstanding missing range checks) below: private String[] alphabetIndex = new String["A", "B"...]; public String getLetterAtIndex(int index1Based) { return alphabetIndex[index1Based-1]; }
- high_na_euv 2y agoSwitch is useful for simple code dependent on e.g kind or expression, not just as a mapper
- kaba0 2y agoThese are switch expressions. And there is absolutely a need for them, especially with records. They provide a much safer and better composing way to write data-oriented code.
- SillyUsername 2y agoFrom a holistic point of view new developers often bemoan Java being too large and complex to learn, which is the opposite of what it used to be (I started at JDK 1.0 in 1995). 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.
- 2y ago
- deleted 2y ago[deleted]