1
的给定类型:什么为T
public static <T> void copy(List<? super T> dest, List<? extends T> src)
我看到这个页面: Confusion over Java generic method type inference
但我仍然困惑,dasblinkenlight说,只要对象传递中是一致的,然后代码应该编译。
这是否意味着第一个参数类型将有助于确定第二个有效的 ?
public class Hello {
public static void main(String[] args){
ArrayList<Animal> dogs = new ArrayList<>();
ArrayList<Marly> marlies = new ArrayList<>();
copy(dogs,marlies);
}
public static <T> void copy(List<? super T> dest, List<? extends T> src{
}
}
class Animal{}
class Dog extends Animal { }
class Beagle extends Dog { }
class Marly extends Beagle{ }
几乎所有可能的方法我都围绕它编译,只要首先是在继承层次更高的这两个列表改变。
有人可以帮助解释远一点
没有这个职位澄清一点? https://stackoverflow.com/questions/1368166/what-is-a-difference-between-super-e-and-extends-e – csunday95
明白了。所以我认为在这样的情况下确实没有T,并且真正重要的是方法体中会发生什么以及如何将这些类相互关联是正确的。 – madmax