r/androiddev • u/pjmlp • Mar 03 '20
Java 14 Arrives with a Host of New Features
https://blogs.oracle.com/javamagazine/java-14-arrives-with-a-host-of-new-features0
u/butterblaster Mar 03 '20 edited Mar 03 '20
Why are they introducing an alternative to colons for switch statements? Seems like they’re just adding noise.
Edit: I mean, why introduce the arrow syntax for both switch statements and expressions? Isn’t one syntax (colons) good enough?
3
u/dpash Mar 03 '20 edited Mar 03 '20
Because otherwise you have to remember that two syntaxes can be used with expressions, but one of them doesn't work with statements. It reduces the mental load of the language. If you don't like it, don't use it. You can continue using colon syntax.
1
u/butterblaster Mar 03 '20
Sorry, I mis-stated. Why did they introduce a second syntax at all? Couldn’t a switch expression use just colons? From what I’m seeing, it’s increasing mental load from what we had before.
1
u/dpash Mar 03 '20
For multiple reasons. In particular, the new syntax does not have fall-through. They also have block scopes. These are not true of the old syntax.
1
u/butterblaster Mar 04 '20
Ah, so using arrows changes the behavior. Makes sense, then.
2
u/dpash Mar 04 '20
Yes, they made a mistake in too readily copying the C/C++ switch statement back in 1995 thinking that it would be easier for C++ developers to move over, but it is full of places where you can shoot yourself in the foot. The new syntax is designed to make it harder to accidentally introduce bugs, like forgetting to include a
breakstatement.1
u/pjmlp Mar 04 '20
It wasn't a mistake per se, rather trying to cater to the C and C++ folks regarding language adoption.
Just like C's copy-paste compatibility is seen as mistake in modern C++, due to the security exploits it opens up, however it was a huge factor regarding C++'s adoption in the mid-90's.
14
u/ballzak69 Mar 03 '20
Remind me in 10 years when it's usable on Android.