I am learning Java generics and tried the below code
class A {
public <T> void pick(T a, T b){
System.out.println(b.getClass().getName());
System.out.println(a.getClass().getName());
}
}
new A().pick("abc", 5);
Here my idea is that pick
function's parameter should be of same type as both are T
.
However when I am calling it using new A().pick("abc",5)
there are no compile time error.
Rather I get the result b is Integer class
and a is String class
Can any one help me with this concept.