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

前端 未结 10 2117
隐瞒了意图╮
隐瞒了意图╮ 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 13:03

    Nope, what you have is fine. You could also do this as a formula (sliderVal < 5 ? (1.0 - 0.1 * sliderVal) : 1.0) or use a Map, but what you have is fine.

提交回复
热议问题