Here you can find the source of isCompatible(Class> type0, Class> type1)
private static boolean isCompatible(Class<?> type0, Class<?> type1)
//package com.java2s; //License from project: Apache License import java.util.HashMap; import java.util.Map; public class Main { private static final Map<Class<?>, Class<?>> PRIMITIVE_TO_WRAPPER = new HashMap<Class<?>, Class<?>>(); private static boolean isCompatible(Class<?> type0, Class<?> type1) { if (type0.getName().equals(type1.getName())) { return true; }//from ww w . j av a2 s . c om if (type0.isPrimitive()) { return isCompatible(PRIMITIVE_TO_WRAPPER.get(type0), type1); } if (type1.isPrimitive()) { return isCompatible(type0, PRIMITIVE_TO_WRAPPER.get(type1)); } return type0.isAssignableFrom(type1); } }