private Constructor < T > findNoArgConstructor ( Class < T > dataClass ) { Constructor < T > [ ] constructors ; try { @ SuppressWarnings ( "unchecked" ) Constructor < T > [ ] consts = ( Constructor < T > [ ] ) dataClass . getDeclaredConstructors ( ) ; // i do this [grossness] to be able to move the Suppress inside the method constructors = consts ; } catch ( Exception e ) { throw new IllegalArgumentException ( "Can't lookup declared constructors for " + dataClass , e ) ; } for ( Constructor < T > con : constructors ) { if ( con . getParameterTypes ( ) . length == 0 ) { if ( ! con . isAccessible ( ) ) { try { con . setAccessible ( true ) ; } catch ( SecurityException e ) { throw new IllegalArgumentException ( "Could not open access to constructor for " + dataClass ) ; } } return con ; } } if ( dataClass . getEnclosingClass ( ) == null ) { throw new IllegalArgumentException ( "Can't find a no-arg constructor for " + dataClass ) ; } else { throw new IllegalArgumentException ( "Can't find a no-arg constructor for " + dataClass + ". Missing static on inner class?" ) ; } }
Locate the no arg constructor for the class .