You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Phil Steitz (JIRA)" <ji...@apache.org> on 2010/03/13 21:30:27 UTC
[jira] Updated: (MATH-337) Equals methods rely on catching
ClassCastException rather than using instanceof check
[ https://issues.apache.org/jira/browse/MATH-337?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Phil Steitz updated MATH-337:
-----------------------------
Fix Version/s: 2.1
> Equals methods rely on catching ClassCastException rather than using instanceof check
> -------------------------------------------------------------------------------------
>
> Key: MATH-337
> URL: https://issues.apache.org/jira/browse/MATH-337
> Project: Commons Math
> Issue Type: Improvement
> Reporter: Sebb
> Priority: Minor
> Fix For: 2.1
>
>
> Several of the equals methods rely on catching ClassCastException rather than using an instanceof check.
> For example:
> {code}
> SimplexTableau.equals(Object){
> if (this == other) {
> return true;
> }
> if (other == null) {
> return false;
> }
> try {
> SimplexTableau rhs = (SimplexTableau) other;
> etc.
> } catch (ClassCastException ex) {
> return false;
> }
> }
> {code}
> This is likely to be significantly slower if the cast fails. It would be cheaper to do the following:
> {code}
> SimplexTableau.equals(Object){
> if (this == other) {
> return true;
> }
> if (!(other instanceof SimplexTableau)) {
> return false;
> }
> SimplexTableau rhs = (SimplexTableau) other;
> etc.
> }
> {code}
> Note that the null check is no longer needed; it is replaced by the instanceof check.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.