AggregationUtils implements Serializable { @SuppressWarnings("unchecked") public static <T extends Number, I extends Number> Double add(T o1, I o2){ if(o1 == null || o2 == null){ return null; } return o1.doubleValue() + o2.doubleValue(); } private  AggregationUtils(); @SuppressWarnings("unchecked") // both types are the same and extends from Comparable static int compare(T o1, I o2); @SuppressWarnings("unchecked") // manually checked type security static Double add(T o1, I o2); @SuppressWarnings("unchecked") // manually checked type security static Double subtract(T o1, I o2); @SuppressWarnings("unchecked") // manually checked type security static Double multiply(T m1, I m2); @SuppressWarnings("unchecked") // manually checked type security static Double divide(T divided, I divider);  }
@Test public void add() { assertEquals(2, AggregationUtils.add(1, 1), delta); assertEquals(2, AggregationUtils.add(1L, 1L), delta); assertEquals(2, AggregationUtils.add(1F, 1F), delta); assertEquals(2, AggregationUtils.add(1D, 1D), delta); assertEquals(2, AggregationUtils.add(1D, 1L), delta); }