I have the following code and it doesn't work: the error both methods have same erasure appears.
public class Foo<V> { public static void main(String[] args) { } public void Bar(V value) { } public void Bar(Object value) { } } Also I have this code:
public class Foo<V> { public static void main(String[] args) { } public void Bar(B value) { } public void Bar(A value) { } } class A { } class B extends A { } And this works. In the first case V is a child of Object, just like in the second case B is a child of A. Then why the first case results in error, while the second compiles successfully?
EDIT: What should I do to achieve method overloading, without raising an error?
Bar(V value)toBar(Object value).Vis a child ofObject". No.Vis a type parameter that can be any subclass ofObject, but alsoObjectitself. So as far as compiler is concerned,Vcould be anObjectand hence there is no difference between the two methods.Foo<Object>but not onFoo<AnythingElse>.