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

前端 未结 5 1359
遥遥无期
遥遥无期 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:39

    It's offten better getting already implemented iso create owns. See at Min / Max function with two Comparable. Simplest is org.apache.commons.lang.ObjectUtils:

    Comparable a = ...;
    Comparable b = ...;
    Comparable min = ObjectUtils.min(a, b);
    

提交回复
热议问题