我想了解以下类型的语法。
Example:
public interface A < T extends A < T> > {
}
这个接口的逻辑是什么?
这将按如下方式使用:
class X implements A<X> { /* ... */ }
换句话说,你被迫将参数设置为A
班上X
本身,以及类似的东西class X implements A<Unrelated>
是禁止的。
这种结构使接口能够访问X
通过泛型参数,类型限制确保它不会被滥用。例如,T
现在可以假设公开所有方法A
does.
Note that this construction is formally somewhat similar to the curiously recurring template pattern http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern in C++ (although it is technically quite different). In both languages it allows the "base class" to reason about its ultimate derived usage.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)