given the common interface:
public interface I<E> { public int interfaceMethod(E s); }
and a general class that implements an interface
public class A<T> implements I<T> { private T val; public A(T x) { val = x; } public int interfaceMethod(T val) {
Why does the following work?
public class Run { public static void main(String[] args) { A a = new A<String>("hello"); System.out.println(a.interfaceMethod(100)); \\ returns 0 } }
I expected that the type parameter T the interfaceMethod method, as defined in class A , limits the method to arguments that are of the same type as constructor A (in this case String ).
Why does a.interfaceMethod not require an argument of type String ?
source share