Here you can find the source of add(T a, T b)
@SuppressWarnings("unchecked") public static <T extends Number> T add(T a, T b)
//package com.java2s; //License from project: Open Source License import java.math.BigDecimal; public class Main { @SuppressWarnings("unchecked") public static <T extends Number> T add(T a, T b) { if (a instanceof Integer) { return (T) new Integer((Integer) a + (Integer) b); }//from w w w. j a v a2 s . c o m if (a instanceof Long) { return (T) new Long((Long) a + (Long) b); } if (a instanceof Double) { return (T) new Double((Double) a + (Double) b); } if (a instanceof BigDecimal) { return (T) ((BigDecimal) a).add((BigDecimal) b); } throw new IllegalArgumentException("Type not supported: " + a.getClass().getSimpleName()); } }