java why should equals method input parameter be Object

后端 未结 6 925
别那么骄傲
别那么骄傲 2020-12-09 10:42

I\'m going through a book on data structures. Currently I\'m on graphs, and the below code is for the vertex part of the graph.

class Vertex{
    /         


        
6条回答
  •  死守一世寂寞
    2020-12-09 11:11

    It's because this method existed before generics, so for backward compatabitity it has to stay this way.

    The standard workaround to impose type is:

    return obj instanceof MyClass && ;
    

提交回复
热议问题