Jeet Jain wrote:In the 2nd file it gives an error at (4) saying it wants M instead of N. When I make it M it gives error at (3) saying same erasure as (1). I'm confused.
Stephan van Hulst wrote:set(N) however isn't valid, because method parameters are invariant, and N is not M. Instead, the method would be overloaded, but since the parameters are generic, they will be erased after compile time, leaving the class with two overloaded versions of set(Object), which is illegal.
Jeet Jain wrote:But then doesn't that mean that at compile time it seems like overloading but at runtime , after erasure, it has overriden it (not overloaded). Why is that wrong?
Also, how come the 1st time the compiler allowed (3) and gave error at (4) but when the error at (4) was cured by changing N to M it gave error at (3)? Why didnt it give an error the 1st time?
No matter. Try again. Fail again. Fail better. This time, do it with this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|