Skip to main content

Ctrl-c, Ctrl-v

Posted by erikhatcher on June 11, 2003 at 3:02 PM PDT

I went to Joshua Bloch's and Neal Gafter's More Programming Puzzlers session. It was fantastic! I won't embarrass myself with how many of the ten puzzlers I got wrong. One piece of advice Bloch gave was to "copy-and-paste" declarations to avoid issues with mis-overridden methods like this:

    public class Name {
        public boolean equals(Name o) { ... }
        // hashCode omitted
    }

The error is that the equals method of Object is not really overridden because the signature should be public boolean equals(Object o).

I think the advice of copy-and-paste really should be more along the lines of "use great tools". In IntelliJ IDEA, for example, I'd simply hit Ctrl-o, select the equals method under Object, and press return - voila, method signature created automatically. In fact, several mistakes that were pointed out in this presentation could be avoided with the right tools.

Related Topics >>