What is the benefit of extending a generic by specifying the new type as actual type of generic

前端 未结 5 731
逝去的感伤
逝去的感伤 2021-01-05 14:27

I saw this pattern somewhere:

class A extends B {

}

This structure is a little unusual to extend a generic by specifying the new

5条回答
  •  庸人自扰
    2021-01-05 15:01

    Take this example:

    E extends Comparable
    

    This means that E must be a type that knows how to compare to itself, hence, the recursive type definition.

    Don't know if it has any official names, but I would call it recursive generic type pattern.

提交回复
热议问题