Here you can find the source of calculateDistancePrimitive(Class> a, Class> b)
static float calculateDistancePrimitive(Class<?> a, Class<?> b)
//package com.java2s; //License from project: LGPL import java.util.Arrays; import java.util.List; public class Main { /**/*from w ww . j av a 2s . c om*/ * Array that contains the primitive wrappers in the order they can be * converted without a type-cast. */ private static final List<Class<?>> PRIMITIVE_WIDENING = Arrays.asList(Byte.class, Short.class, Character.class, Integer.class, Long.class, Float.class, Double.class); static float calculateDistancePrimitive(Class<?> a, Class<?> b) { // Nothing can be converted to a char or a boolean. if (b == Character.class || b == Boolean.class) return -1F; // char acts like a short. if (a == Character.class) a = Short.class; int indexA = PRIMITIVE_WIDENING.indexOf(a); int indexB = PRIMITIVE_WIDENING.indexOf(b); if (indexA < 0 || indexB < 0) return -1F; return (indexB - indexA) / 10F; } }