Overriding the java equals() method - not working?

后端 未结 8 1240
花落未央
花落未央 2020-11-22 02:33

I ran into an interesting (and very frustrating) issue with the equals() method today which caused what I thought to be a well tested class to crash and cause a

8条回答
  •  梦如初夏
    2020-11-22 03:08

    Consider:

    Object obj = new Book();
    obj.equals("hi");
    // Oh noes! What happens now? Can't call it with a String that isn't a Book...
    

提交回复
热议问题