Redundant Parentheses

Download java eBook

Example

return flag ? "yes" : "no";

String cmp = (flag1 != flag2) ? "not equal" : "equal";

// Don't do this
return (flag ? "yes" : "no");
  • Redundant grouping parentheses (i.e. parentheses that does not affect evaluation) may be used if they improve readability.
  • Redundant grouping parentheses should typically be left out in shorter expressions involving common operators but included in longer expressions or expressions involving operators whose precedence and associativity is unclear without parentheses. Ternary expressions with non-trivial conditions belong to the latter.
  • The entire expression following a return keyword must not be surrounded by parentheses.

Stats

Contributors: 2
2016-10-25
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook