So I'm working in Java and I want to declare a generic List.
So what I'm doing so far is List<T> list = new ArrayList<T>();
But now I want to add in an element. How do I do that? What does a generic element look like?
I've tried doing something like List.add("x") to see if I can add a string but that doesn't work.
(The reason I'm not declaring a List<String> is because I have to pass this List into another function that only takes List<T> as an argument.
List<T>, which will likely be a generic argument to the class it belongs to. You're likely the one defining what thisTis somewhere in your own code.List<Object> list = new ArrayList<Object>(), and after you get an element byget(int index)downcast it to the desire class which compatible to another function.