'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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|