I want to create a class that can be made without any parameters, and has a method that takes a list of any object and behaves like this:
List<String> list1 = Arrays.asList(new String [] {"a","b"});
List<String> result1 = myClass.myMethod(list1);
List<Integer> list2 = Arrays.asList(new String [] {1,2});
List<Integer> result1 = myClass.myMethod(list2);
Here's my attempt after reading briefly about Java generics:
public class myClass<T> {
public List<T> myMethod(List<T> input) {
...
return input; // just an example
}
Why doesn't this work?