private static Constructor < ? > getDeclaredConstructor ( Class < ? > implementationClass ) { if ( implementationClass == null ) { return null ; } Constructor < ? > [ ] declaredConstructors = ( Constructor < ? > [ ] ) implementationClass . getDeclaredConstructors ( ) ; if ( declaredConstructors . length == 0 ) { throw new BugError ( "Invalid implementation class |%s|. Missing constructor." , implementationClass ) ; } Constructor < ? > constructor = null ; for ( Constructor < ? > declaredConstructor : declaredConstructors ) { // synthetic constructors are created by compiler to circumvent JVM limitations, JVM that is not evolving with // the same speed as the language; for example, to allow outer class to access private members on a nested class // compiler creates a constructor with a single argument of very nested class type if ( declaredConstructor . isSynthetic ( ) ) { continue ; } if ( declaredConstructor . getParameterTypes ( ) . length == 0 ) { continue ; } if ( declaredConstructor . getAnnotation ( Test . class ) != null ) { continue ; } if ( constructor != null ) { throw new BugError ( "Implementation class |%s| has not a single constructor with parameters." , implementationClass ) ; } constructor = declaredConstructor ; } if ( constructor == null ) { constructor = declaredConstructors [ 0 ] ; } constructor . setAccessible ( true ) ; return constructor ; }
Get implementation class constructor . Managed class mandates a single constructor with parameters no matter if private or formal parameters count . If both default constructor and constructor with parameters are defined this method returns constructor with parameters . Returns null if implementation class is missing .