public static void throwArgMismatchException ( IllegalArgumentException exceptionToWrap , String featureName , Class [ ] actualParameters , Object [ ] args ) { String argTypes = "(" ; for ( int i = 0 ; i < actualParameters . length ; i ++ ) { Class aClass = actualParameters [ i ] ; if ( i > 0 ) { argTypes += " ," ; } argTypes += aClass . getName ( ) ; } argTypes += ")" ; String rttTypes = "(" ; for ( int i = 0 ; i < args . length ; i ++ ) { if ( i > 0 ) { rttTypes += " ," ; } if ( args [ i ] != null ) { rttTypes += args [ i ] . getClass ( ) . getName ( ) ; } else { rttTypes += "null" ; } } rttTypes += ")" ; throw new RuntimeException ( "Tried to pass values of types: " + rttTypes + " into " + featureName + " that takes types " + argTypes , exceptionToWrap ) ; }
This method can be used to provide a more informative type - mismatch exception message than the standard java reflection does with its IllegalArgumentException .