【问题标题】:Java Method Definition Compile Error WilcardJava 方法定义编译错误通配符
【发布时间】:2019-08-15 10:41:55
【问题描述】:

我有一个名为 getExcludeMethodList() 的方法,我在 Eclipse 上遇到编译错误。

我的方法签名

private List<String> getExcludeMethodList(List<T> data, List<String> filteredList) {

 List<String> excludeList= new ArrayList<>();

    //.........

     return excludeList;
}

但是eclipse强制我使用

private static <T> List<String> getExcludeMethodList(List<T> data, List<String> filteredList) {
List<String> excludeList= new ArrayList<>();

    //.........

     return excludeList;
    }

但是当我使用“?”问题字符通配符对我有用,我不知道为什么会这样?

private static List<String> getExcludeMethodList(List<?> data, List<String> filteredList) {

【问题讨论】:

  • 如果遇到编译错误,请分享错误信息。

标签: java generics wildcard


【解决方案1】:

是的,您必须声明类型&lt;T&gt;,它代表具体的未绑定类型? 代表您不必声明的任何类型

【讨论】:

    猜你喜欢
    • 2013-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-13
    • 1970-01-01
    • 2021-02-28
    • 2012-10-21
    相关资源
    最近更新 更多