Matrix 'conditional Logic can be removed' checkstyle

checkstyle, java

Solution

It is complaining about this part right here :

    if(a.getNumberofColumns() != b.getNumberOfRows())
    {
        return false;
    }
    else
    {
        return true;
    }

Whenever you see yourself writing code like this you can easily replace it with a single line by just returning the condition from the if statement:

return a.getNumberofColumns() == b.getNumberOfRows();

This statement will return `true` if the the number of columns for a and rows for b are equal, and `false` otherwise.

Problem

``` public static boolean isCompatibleForMultiplcation(final Matrix a, final Matrix b) { if (a == null) { throw new IllegalArgumentException("a cannot be null"); } if (b == null) { throw new IllegalArgumentException("b cannot be null"); } if(!(a.getNumberofColumns()== b.getNumberOfRows())) { return false; } else { return true; } } ``` I am getting a 'Conditional Logic can be removed argument in checkstyle for the following method. I cannot seem to figure out why... Can someone give me a pointer?

Original source