【问题标题】:What is the difference between these 2 methods [duplicate]这两种方法有什么区别[重复]
【发布时间】:2017-08-18 01:00:25
【问题描述】:

这两种工作方式相似的方法有什么区别。谁能解释一下具体的区别?

**Accepts the list with all Number Type**
public static double sum(List<? extends Number> list)
{
    double sum = 0;
    for(Number n : list){
        sum += n.doubleValue();
    }
    return sum;
}


// Accepts the list with all Number Type
public static <T extends Number> double sum1(List<T> list){
    double sum = 0;
    for(T n : list){
        sum += n.doubleValue();
    }
    return sum;
}

【问题讨论】:

    标签: java generics


    【解决方案1】:

    没有区别。它们在完全相同的输入上的工作方式完全相同。

    【讨论】:

      猜你喜欢
      • 2013-09-08
      • 2019-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-14
      相关资源
      最近更新 更多