5 ms·
This is inconsistent and no longer Java. The -> is not a good idea and break <something> should be return <something>. The -> throw e; "sugar" is just ridiculo
by nikolay 9y ago
This is inconsistent and no longer Java.
The -> is not a good idea and break <something> should be return <something>. The -> throw e; "sugar" is just ridiculous!
- SolaDev 9y agoIMO, return <something> may be ambiguous in switch expression.
- nikolay 9y agoYeah, but return gives the value of an expression and break is a control flow keyword.
- Macha 9y ago-> is already in for lambdas.
- nikolay 9y agoYeah, but this is not a function.
- merb 9y agothe only problem/wierdness might happen with -> is if switch will return a lambda. i.e. case "Foo" -> () -> "newfoo" looks silly at first. well scala supports that and it looks strange at first but in functional programming, these patterns aren't as strange as they first look.
- nikolay 9y agoPeople already use return if the switch is the last statement in a function, so, all this "sugar" is only confusing, inconsistent, and not improving the readability or the learning curve.
- merb 9y agowell I think the sugar is fine. just the none sugar is kinda.. wierd. who would ever write: 'case "foo": break 1' it's just unnecessary. (but they probably do it for backwards compat or so, no idea..)
- int_19h 9y agoThey can't use "return", because it already means something else in Java, including inside a switch statement.
- earenndil 9y agobreak <something> should not be return <something>. What if you actually want to return something from within a switch? More to the point, what about existing code that uses return in a switch statement.
- nikolay 9y agoThat would be a terrible coding practice!