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

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

    Why not just

    private double translateSlider(int sliderval) {
    if(sliderval > 4 || sliderval < 0)
        return 1.0d;
    return (1.0d - ((double)sliderval/10.0d));
    }
    

    Or similar?

提交回复
热议问题