Regarding Java switch statements - using return and omitting breaks in
each case
Given this method, does this represent some egregious stylistic or
semantic faux pas:
private double translateSlider(int sliderVal) {
switch (sliderVal) {
case 0:
return 1.0;
case 1:
return .9;
case 2:
return .8;
case 3:
return .7;
case 4:
return .6;
default:
return 1.0;
}
}
It's clearly not in line with the Java tutorials here.
However, It's clear, concise and so far has yielded exactly what I need.
Is there a compelling, pragmatic reason to create a local variable, assign
a value to it within each case, add a break to each case and return the
value at the end of the method?
No comments:
Post a Comment