Java tutorial
//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; } 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); } }