Given this simple class:
import java.util.Collection;
public class GenericTest<T> {
public Collection<String> getKeys() {
return null;
}
public void copy(GenericTest a_from) {
for (String x : a_from.getKeys()) {
}
}
}
I am getting the following compile error, but don't understand why.
error: incompatible types
for (String x : a_from.getKeys()) {
required: String
found: Object
The error goes away if I change the parameter to the copy() method to GenericTest<T>, but that is not what I want. The copy() method is valid on any type of GenericTest, not just GenericTest<T>.