4 ms·
As another comment mention, they did use && in the 2nd preview, but then switched it, so you're right, it must have been confusing. FWIW, though, I don't find
by hn_throwaway_99 4y ago
As another comment mention, they did use && in the 2nd preview, but then switched it, so you're right, it must have been confusing.
FWIW, though, I don't find it "bizarre". While it's not a boolean expression per Java, at least in my mind it serves the same purpose: "in the case that thing x is of type SomeType and ...some other thing about ((SomeType)x) is true...".
I think it's a tough choice, I'm sure they were probably not wanting to add a new keyword, but at the end of the day "when" is so familiar to anyone who's ever written SQL (which I'm guessing is most Java devs) so seems like a good choice.
- anyfoo 4y ago> While it's not a boolean expression per Java, at least in my mind it serves the same purpose But if some construct looks the same, but is not the same, and worse, only "somewhat" the same, you get confusing behavior. At least for newcomers, or even just software engineers who just don't care about language grammar that deeply (which I imagine are not only a lot, but also a lot of the Java target audience specifically). Case in point, the author I was replying to wondered in a followup whether && would/should still act like a shortcut-and operator would, or not. There is definitely some subjectivity to it, but personally I much prefer if different constructs look clearly different. Any ambiguity is squashed immediately, and in the case of "when" it's still fully clear how it works. I'm also okay with the "if" variant, because while it reuses a keyword, it's clearly a different "if".