Java Class Type Check isAssignableFrom(Class clazzA, Class clazzB)

Here you can find the source of isAssignableFrom(Class clazzA, Class clazzB)

Description

is Assignable From

License

Open Source License

Declaration

private static boolean isAssignableFrom(Class clazzA, Class clazzB) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010 Markus Alexander Kuppe.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://  ww  w. ja v a 2  s .com
 *     Markus Alexander Kuppe (ecf-dev_eclipse.org <at> lemmster <dot> de) - initial API and implementation
 ******************************************************************************/

import java.util.*;

public class Main {
    private static Map convertor = new HashMap();

    private static boolean isAssignableFrom(Class clazzA, Class clazzB) {
        if (!(clazzA.isPrimitive() ^ clazzB.isPrimitive())) {
            return clazzA.isAssignableFrom(clazzB);
        } else if (clazzA.isPrimitive()) {
            final Class oClazzA = (Class) convertor.get(clazzA);
            return oClazzA.isAssignableFrom(clazzB);
        } else {
            final Class oClazzB = (Class) convertor.get(clazzB);
            return clazzA.isAssignableFrom(oClazzB);
        }
    }
}

Related

  1. isAssignable(final Class target, final Class source)
  2. isBasicType(Class clazz)
  3. isClassBelowPackage(Class theClass, List packageList)
  4. isCollection(Class clazz)
  5. isCollection(Class cls)