import java.util.*;
class GenericClass<T>{
ArrayList<T> list = new ArrayList<>();
void add(T obj){
list.add(obj);
}
void callMethod(){
list.get(0).display();
}
}
class Test{
public void display(){
System.out.println("HELLO WORLD");
}
}
class Main{
public static void main(String... args){
GenericClass<Test> gen = new GenericClass<Test>();
Test t = new Test();
gen.add(t);
gen.callMethod();
}
}
I have created these simple classes. The Test class object is passed to add function, but I can use the method display. It gives the error - Can't find symbol display()
When I just print the object, I can see that it it prints the correct object. Please help, I'm very new to java. Thank you