How to implement a generic `max(Comparable a, Comparable b)` function in Java?

前端 未结 5 1358
遥遥无期
遥遥无期 2020-12-18 20:17

I\'m trying to write a generic max function that takes two Comparables.

So far I have

public static &g         


        
5条回答
  •  臣服心动
    2020-12-18 20:26

    You get this error because Comparable basically says that it is comparable to something without any specifics. You should write Comparable instead, so the compiler would know that type T is comparable to itself.

提交回复
热议问题