Comparing two classes by its types or class names

前端 未结 7 1216
耶瑟儿~
耶瑟儿~ 2021-02-01 15:34

There is need to compare two objects based on class they implement? When to compare using getClass() and when getClass().getName()? Is there any differ

7条回答
  •  别跟我提以往
    2021-02-01 15:40

    You can use the inbuilt method of Class :

    if(nextMonster.getClass().isAssignableFrom(monster.getClass()))
    

提交回复
热议问题