问题描述
为什么
$ b的特定 code>在这种情况下。
因为?是通配符,所以?在你的方法声明中的类声明和?中,因此它不会被编译。只需列表<?>
第一种场景 >表示整个类可以正确处理一个类型的 Bar 每个实例。
界面Foo< T延伸栏> {
列表< T>得到();
第二种场景允许每个实例可在任何子类型 Bar
上进行操作
接口Foo {
列表< ;?扩展Bar> get()
}
why does
public interface ArrayOfONEITEMInterface <T extends ONEITEMInterface>{ public List<T> getONEITEM(); }compile, but not
public interface ArrayOfONEITEMInterface <? extends ONEITEMInterface>{ public List<?> getONEITEM(); }what is the difference between ? and T in class and method signatures?
解决方案? is a wildcard and means any sublass of ONEITEMInterface including itself.
T is a specific implementation of ONEITEMInterface in this case.
Since ? is a wildcard, there is no relation between your ? in the class declaration and the ? in your method declaration hence it won't compile. Just List<?> getONEITEM(); will compile though.
The first scenario means the entire class can handle exactly one type of Bar per instance.
interface Foo<T extends Bar> { List<T> get(); }The second scenario allows each instance to operate on any subtype of Bar
interface Foo { List<? extends Bar> get() }
这篇关于有什么区别?和T在类和方法签名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!