public static boolean areTypesCompatible ( Class [ ] typeArguments , List < Class > classToCompare ) { if ( classToCompare . size ( ) == 0 ) { // in this case the type doesn't specify type arguments, so this is the equivalent of using Object return true ; } else { if ( classToCompare . size ( ) != typeArguments . length ) { return false ; } else { for ( int i = 0 ; i < classToCompare . size ( ) ; i ++ ) { Class left = classToCompare . get ( i ) ; Class right = typeArguments [ i ] ; if ( right == Object . class ) { continue ; } if ( left != right && ! left . isAssignableFrom ( right ) ) { return false ; } } } } return true ; }
Are the given types compatible .