Determine if classes can be assigned from - Java Reflection

Java examples for Reflection:Super Class

Description

Determine if classes can be assigned from

Demo Code


//package com.java2s;

public class Main {
    /**//from  w  ww.  j a  va 2 s.  c o m
     * Determine if classes can be assigned from
     *
     * @param c1 first array of classes
     * @param c2 second array of classes
     * @return true if c1 array can be assigned from c2 array
     */
    public static boolean isAssignable(Class[] c1, Class[] c2) {
        if (c1 == null || c2 == null)
            return false;

        if (c1.length != c2.length)
            return false;

        for (int i = 0; i < c1.length; i++) {
            if (!c1[i].isAssignableFrom(c2[i]))
                return false;
        }

        return true;
    }
}

Related Tutorials