Java泛型上界通配符限制

Java泛型上界通配符限制,java,generics,Java,Generics,有人能解释一下这两段代码之间的区别吗 (一) 私人收藏getAnimal(){ 返回null; } (二) private CollectionCollection比CollectionPECS更具限制性——基本上,你可以从第二个动物中取出一个Animal,但不能放入任何类型的对象。如果这不是预期的使用模型,那么使用第一个。 private Collection<Animal> getAnimal() { return null; } private Collection

有人能解释一下这两段代码之间的区别吗
(一)

私人收藏getAnimal(){
返回null;
}
(二)

private Collection
Collection
CollectionPECS更具限制性——基本上,你可以从第二个动物中取出一个
Animal
,但不能放入任何类型的对象。如果这不是预期的使用模型,那么使用第一个。
private Collection<Animal> getAnimal() {
    return null;
}
private Collection<? extends Animal> getAnimal() {
    return null;
}
public static double sum(List<? extends Number> numberlist) {
  double sum = 0.0;
  for (Number n : numberlist) sum += n.doubleValue();
  return sum;
 }
 public static void main(String args[]) {
  List<Integer> integerList = Arrays.asList(1, 2, 3);
  System.out.println("sum = " + sum(integerList));

  List<Double> doubleList = Arrays.asList(1.2, 2.3, 3.5);
  System.out.println("sum = " + sum(doubleList));
 }
public static double sum(List<Number> numberlist) {
      double sum = 0.0;
      for (Number n : numberlist) sum += n.doubleValue();
      return sum;
   }
The method sum(List<Number>) in the type NewMain is not applicable for the arguments (List<Double>)
The method sum(List<Number>) in the type NewMain is not applicable for the arguments (List<Integer>)