Boolean methods and variables

When you have some non-trivial boolean statement used in if like: private void evict(Data data) { // ... if (data.getDate() >= MATURITY_DATE && data.type == DataType.UNDEF) { // do the eviction } } To make it easier to read and maintain, it’s a good idea to extract it to a local variable or method: private void evict(Data data) { // ... boolean isEligibleForEviction = data.getDate() >= MATURITY_DATE && data.type == DataType....

July 20, 2016 · 3 min