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

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

    Assigning a value to a local variable and then returning that at the end is considered a good practice. Methods having multiple exits are harder to debug and can be difficult to read.

    That said, thats the only plus point left to this paradigm. It was originated when only low-level procedural languages were around. And it made much more sense at that time.

    While we are on the topic you must check this out. Its an interesting read.

提交回复
热议问题