Here you can find the source of max(T a, T b)
Parameter | Description |
---|---|
T | the object type |
a | item that compareTo is called on, may be null |
b | item that is being compared, may be null |
public static <T extends Comparable<? super T>> T max(T a, T b)
//package com.java2s; //License from project: Apache License public class Main { /**//from w w w . j a v a 2 s .c om * Compares two objects finding the maximum. * * @param <T> the object type * @param a item that compareTo is called on, may be null * @param b item that is being compared, may be null * @return the maximum of the two objects, null if both null */ public static <T extends Comparable<? super T>> T max(T a, T b) { if (a != null && b != null) { return a.compareTo(b) >= 0 ? a : b; } if (a == null) { if (b == null) { return null; } else { return b; } } else { return a; } } }