Java Reflection Assignable isCompatible(Class actualType, Class parameterType)

Here you can find the source of isCompatible(Class actualType, Class parameterType)

Description

is Compatible

License

Apache License

Declaration

public static boolean isCompatible(Class actualType, Class parameterType) 

Method Source Code

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

import java.util.HashMap;

import java.util.Map;

public class Main {
    /**/*from w w  w  .j  a v  a2  s .co m*/
     * Map from primitive type to wrapper type.
     */
    private static final Map _primitiveMap = new HashMap();

    public static boolean isCompatible(Class actualType, Class parameterType) {
        if (actualType.isAssignableFrom(parameterType))
            return true;

        // Reflection fudges the assignment of a wrapper class to a primitive
        // type ... we check for that the hard way.

        if (actualType.isPrimitive()) {
            Class wrapperClass = (Class) _primitiveMap.get(actualType);

            return wrapperClass.isAssignableFrom(parameterType);
        }

        return false;
    }
}

Related

  1. isAssignableFrom(Class to, Class from)
  2. isAssignableFrom(Class toClass, Class fromClass)
  3. isAssignableValue(Class type, Object value)
  4. isAssignableValue(Class type, Object value)
  5. isClassAssignableFrom(Class formal, Class actual)
  6. isCompatible(Class parameterType, Class parameterClass)
  7. isCompatible(Class fromClass, Class toClass)
  8. isCompatible(Class type0, Class type1)
  9. isPromotableFrom(Class assigneeClass, Class valueClass)