I have noticed in some of the code I've perused that peoples' equals()
implementation often starts with:

        public boolean equals(Object o) {
           if(o != null && o instanceof (this class) ....
            ...
        }

      instanceof does an explicit check for null.  If the first parameter is
null, the instanceof will fail.  (See JLS, or better yet, try it out
yourself.)  Therefore the "o != null" can be removed.  It's a minor
optimization, but equals() is called a lot, so a minor optimization there
could lead to nontrivial performance gains.
        I noticed this in most of the java.lang classes, and haven't looked in the
other packages.
--John Keiser

Reply via email to