Regarding Java switch statements - using return and omitting breaks in each case

前端 未结 10 2120
隐瞒了意图╮
隐瞒了意图╮ 2021-02-01 12:29

Given this method, does this represent some egregious stylistic or semantic faux pas:

private double translateSlider(int sliderVal) {
    switch (sliderVal) {
           


        
10条回答
  •  被撕碎了的回忆
    2021-02-01 12:51

    Though the question is old enough it still can be referenced nowdays.

    Semantically that is exactly what Java 12 introduced (https://openjdk.java.net/jeps/325), thus, exactly in that simple example provided I can't see any problem or cons.

提交回复
热议问题