class Genero<T> {
static List<String> getThat() {
return new ArrayList<String>();
}
List<String> getThis() {
return new ArrayList<String>();
}
}
public class Generic {
public static void main(String[] args) {
Genero g = new Genero();
for (String s : g.getThis()) {} //compile error: requiered String, found Object
for (String s : Genero.getThat()) {} //compiles fine
}
}
什么事? 根据类型擦除的想法,我不应该在两种情况下都使用泛型方法getThis / getThat。但我可以将它用于静态方法。为什么呢?