1 year ago
#249047
igol
Class with 2 methods: generic argument vs primitive argument
Suppose you have the following Java class:
public class MyClass<T>{
public void myMethod(int idx){...}
public void myMethod(T idx){...}
}
Now if a class user does:
MyClass<Integer> ref = new MyClass<>();
ref.myMethod(1); // void myMethod(int idx) gets called
ref.myMethod(new Integer(1)); // void myMethod(T idx) gets called
Why does ref.myMethod(1) not call the generic method? Which checks are in place?
Thanks
java
generics
primitive
type-erasure
0 Answers
Your Answer