Java Reflection Assignable isCompatible(Class type0, Class type1)

Here you can find the source of isCompatible(Class type0, Class type1)

Description

is Compatible

License

Apache License

Declaration

private static boolean isCompatible(Class<?> type0, Class<?> type1) 

Method Source Code

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

Related

  1. isAssignableValue(Class type, Object value)
  2. isClassAssignableFrom(Class formal, Class actual)
  3. isCompatible(Class actualType, Class parameterType)
  4. isCompatible(Class parameterType, Class parameterClass)
  5. isCompatible(Class fromClass, Class toClass)
  6. isPromotableFrom(Class assigneeClass, Class valueClass)