The only feasible alternative in this particular case is to grab the conditional operator ?:
.
public String getTemperatureMessage(double temp) {
return temp < 32 ? "Freezing"
: temp < 60 ? "Brr"
: temp < 80 ? "Comfortable"
: "Too hot";
}
Left behind the question how that's readable to starters.
References
- JLS 15.25 Conditional Operator ?:
- The operator is right-associative, thus such nesting of the operator will work "as expected"
Related questions
- To ternary or not to ternary?