1 import java.util.Comparator; 2 3 public class TestComparator { 4 public static void main(String[] args) { 5 GeometricObject g1 = new Rectangle(5, 5); 6 GeometricObject g2 = new Circle(5); 7 8 GeometricObject g = 9 max(g1, g2, new GeometricObjectComparator()); 10 11 System.out.println("The area of the larger object is " + 12 g.getArea()); 13 } 14 15 public static GeometricObject max(GeometricObject g1, 16 GeometricObject g2, Comparator<GeometricObject> c) { 17 return c.compare(g1, g2) > 0 ? g1 : g2; 18 } 19 }