什么< R扩展TableRecord< R>>用Java表示? [英] What does <R extends TableRecord<R>> mean in Java?
问题描述
我正在创建一个JOOQ的界面 TableRecord
I'm creating an interface of JOOQ TableRecord
<R extends TableRecord<R>>
有人能够解释上述行吗?
Would anyone be able to explain the line above?
谢谢
推荐答案
这意味着一个类型为R的类,它实现了接口 TableRecord< R>
It means a class of type R, that implements the interface TableRecord<R>
TableRecord< R>
表示接口绑定到该接口类型R。
TableRecord<R>
means that the interface is bound to the same type R.
一个例子是类:
public class Bla implements TableRecord<Bla>
我承认这看起来有点奇怪,但Java泛型并没有真正区分 extends
和 implements
,这会导致一些混乱。
I admit this seems a bit strange, but Java generics don't really differentiate between extends
and implements
, which leads to some confusion.
至于为什么这个确切的定义,我不太了解上下文,看看它究竟为什么有意义,但它可能是由于接口上的方法签名返回 R
类型的对象(想想工厂):
As to why this exact definition, I don't know enough about the context to see exactly why it makes sense, but it might be due to method signatures on the interface returning objects of type R
(think Factory):
public R createTableRecord(...);
这篇关于什么< R扩展TableRecord< R>>用Java表示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!