Here you can find the source of average(final T p_num1, final T p_num2)
public static <T extends Number> Double average(final T p_num1, final T p_num2)
//package com.java2s; /******************************************************************************* * Copyright (c) 2011 Lab-STICC Universite de Bretagne Sud, Lorient. * All rights reserved. This program and the accompanying materials * are made available under the terms of the CeCILL-B license available * at ://w w w .j a v a 2 s . c o m * en : http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html * fr : http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.html * * Contributors: * Dominique BLOUIN (Lab-STICC UBS), dominique.blouin@univ-ubs.fr ******************************************************************************/ public class Main { public static <T extends Number> Double average(final T p_num1, final T p_num2) { if (p_num1 == null) { return p_num2 == null ? null : p_num2.doubleValue(); } if (p_num2 == null) { return p_num1.doubleValue(); } return (p_num1.doubleValue() + p_num2.doubleValue()) / 2.0; } }