Overriding “equals” method: how to figure out the type of the parameter?

前端 未结 9 1281
栀梦
栀梦 2021-02-05 07:47

I\'m trying to override equals method for a parameterized class.

@Override
public boolean equals(Object obj) {
    if (this == obj)
        return t         


        
9条回答
  •  -上瘾入骨i
    2021-02-05 08:25

    Sadly, you can't do this at compile time; the information is gone. Such are the consequences of type erasure. An alternative is to store the parameter as a Class instance, and then look it up later.

提交回复
热议问题