public static void reverse(List<?> list)
{
List<Object> tmp = new ArrayList<Object>(list);
for (int i = 0; i < list.size(); i++)
{
list.set(i, tmp.get(list.size()-i-1)); // compile-time error , why ?
}
}
I am learning generics . I know this : When a wildcard is used the ? gets replaced with the appropriate type . When reverse() method is called the ? will get replaced and since every type is a subtype of Object , there should be no error . I am looking for a crystal clear explanation . Please help .