Two Laptop Bag
The moose likes Java in General and the fly likes java generics - name clash error Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "java generics - name clash error" Watch "java generics - name clash error" New topic
Author

java generics - name clash error

Amitav Chowdhury
Greenhorn

Joined: Nov 13, 2009
Posts: 10
Can some one tell me why the following code does not compile:


I was under the impression after type erasure the signature of equals method would change
to : public boolean equals(Object value) . Therefore it would be a valid method overriding.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 9939
    
    6

These questions are MUCH easier to answer if you provide the compilation error in its entirety, rather than just saying "compilation error".


Never ascribe to malice that which can be adequately explained by stupidity.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32599
    
    4
Which compiler are you using and what error are you suffering?
Amitav Chowdhury
Greenhorn

Joined: Nov 13, 2009
Posts: 10
I get the following error while compiling the code using javac:

Name clash: The method equals(T) of type Pair<T> has the same erasure as equals(Object) of type Object but does not override it
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19214

When you compile that code the compiler removes all generics information. That T will be turned into Object, so your method will be turned into "public boolean equals(Object)". However, since you didn't override that method it is inherited - because from a source point of view, equals(T) is not the same as equals(Object). So you end up with two methods with identical names and argument types, and that's not allowed.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: java generics - name clash error
 
Similar Threads
need help plss
Equals method.
equals override
equals method
compare variables of an object