Casting in equals method

前端 未结 7 1425
攒了一身酷
攒了一身酷 2020-12-31 09:46

I have a question about overriding the equals method in Java. In my book, I have the following example:

public class Dog{
     private String na         


        
7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-31 10:11

    Because as method parameter obj is Instance of Object class. So in the method body you need to cast obj back to the Dog type.

提交回复
热议问题