What does “Recursive type bound” in Generics mean?

后端 未结 3 1438
悲&欢浪女
悲&欢浪女 2020-12-15 05:58

I am reading the chapter on Generics from Effective Java[Item 27].

There is this paragraph in the book:

It is permissible, though relative

3条回答
  •  旧时难觅i
    2020-12-15 06:19

    What is recursive type bound

    This: >

    Note that the type parameter T is also part of the signature of the super interface Comparable.

    and how does the above piece of code help achieve mutual comparability?

    It ensures that you can only compare objects of type T. Without the type bound, Comparable compares any two Objects. With the type bound, the compiler can ensure that only two objects of type T are compared.

提交回复
热议问题