public static < T > Constructor < T > getNoArgConstructor ( Class < T > clazz ) { try { Constructor < T > ctor = clazz . getDeclaredConstructor ( new Class [ 0 ] ) ; ctor . setAccessible ( true ) ; return ctor ; } catch ( NoSuchMethodException e ) { // lame there is no way to tell if the class is a nonstatic inner class if ( clazz . isMemberClass ( ) || clazz . isAnonymousClass ( ) || clazz . isLocalClass ( ) ) throw new IllegalStateException ( clazz . getName ( ) + " must be static and must have a no-arg constructor" , e ) ; else throw new IllegalStateException ( clazz . getName ( ) + " must have a no-arg constructor" , e ) ; } }
Throw an IllegalStateException if the class does not have a no - arg constructor .