Here you can find the source of isAssignable(final Class> from, final Class> to)
Parameter | Description |
---|---|
from | the type of the source |
to | the type of the destination |
public static boolean isAssignable(final Class<?> from, final Class<?> to)
//package com.java2s; import java.util.Map; public class Main { private static Map<Class<?>, Class<?>> assignable; /**//from w w w .ja v a 2 s . com * Determines if the type from is assignable to the type to. * * @param from the type of the source * @param to the type of the destination * @return true if assignable, false if otherwise */ public static boolean isAssignable(final Class<?> from, final Class<?> to) { assert from != null; assert to != null; if (to.isAssignableFrom(from)) { return true; } else { final Class<?> clazz = assignable.get(from); return clazz.equals(to); } } /** * Determines if the types in c1 are assignable to the types in c2. * * @param c1 the array of types * @param c2 the array of types * @return true if the types in c1 are assignable to the types in c2 */ private static boolean isAssignable(final Class<?>[] c1, final Class<?>[] c2) { if (c1.length == c2.length) { for (int i = c1.length - 1; i >= 0; i--) { if (!c2[i].isAssignableFrom(c1[i])) { return false; } } return true; } return false; } }