I am trying to create a generic class with a method that accepts a generic parameter. Now in another class create a method that will accept an object of that generic class. and call the generic method from new/main class. like below sample code.
public class MainClass {
public static void main(String[] args) {
MainClass gp = new MainClass();
Class1<Integer> cls1=new Class1<>();
gp.method1(cls1);
}
public void method1(Class1<? extends Number> obj2) {
obj2.method(10); //CT error - can't pass integer
}
}
class Class1<T> {
public void method(T arg) {
}
}
I am getting compile time error. I am learning generic. I don't know where I am missing?