What is the best way (pattern) around return method1() || method2() not invoking method2() if method1() returns true?
Example
I’m using this class to bound a table:
class Bounds {
// return true iff bounds changed
boolean set(int start, int end);
}
and I want this function to resize both the rows and columns and return true iff either was modified:
public boolean resizeToFirstCell(Bounds rows, Bounds columns) {
return rows.set(0, 1) || columns.set(0, 1);
}
Use a non-short circuiting (sometimes called “Eager”) operator,
|.You can read more about that in the operator documentation for
||(C# specific link, but still holds true for Java and C++).