查看了在线截取的代码
public Collection<? extends GrantedAuthority> getAuthorities(Integer role) {
List<GrantedAuthority> authList = getGrantedAuthorities(getRoles(role));
return authList;
}
A.谁能告诉我 ?
是什么意思吗?表示什么?
B. <? extends GrantedAuthority>
哪个类正在扩展 GrantedAuthority?
C.在泛型中,我们在<>中提供类类型以确保类型安全,为什么有人想在<>中提供A扩展B?
最佳答案
它是一个通配符,表示任何扩展对象的类型(也包括对象)。
所以你可以说<?>
是 <? extends Object>
的简写
检查Oracle docs for Type Arguments and Wildcards
来自here :
In generic code, the question mark (?), called the wildcard, represents an unknown type. The wildcard can be used in a variety of situations: as the type of a parameter, field, or local variable; sometimes as a return type (though it is better programming practice to be more specific). The wildcard is never used as a type argument for a generic method invocation, a generic class instance creation, or a supertype.
关于java - 的意义?在泛型中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22709444/