Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
2.0
-
None
-
None
Description
Several of the equals methods rely on catching ClassCastException rather than using an instanceof check.
For example:
SimplexTableau.equals(Object){ if (this == other) { return true; } if (other == null) { return false; } try { SimplexTableau rhs = (SimplexTableau) other; etc. } catch (ClassCastException ex) { return false; } }
This is likely to be significantly slower if the cast fails. It would be cheaper to do the following:
SimplexTableau.equals(Object){ if (this == other) { return true; } if (!(other instanceof SimplexTableau)) { return false; } SimplexTableau rhs = (SimplexTableau) other; etc. }
Note that the null check is no longer needed; it is replaced by the instanceof check.