private Optional tryCreate ( Constructor < ? > constructor ) { Object [ ] args = new Object [ constructor . getParameterCount ( ) ] ; Object arg ; Optional < Object > resolved ; int i = 0 ; for ( Parameter parameter : constructor . getParameters ( ) ) { resolved = context . resolve ( parameter ) ; if ( ! resolved . isPresent ( ) ) { return Optional . empty ( ) ; } arg = resolved . value ( ) ; args [ i ++ ] = arg ; } return Optional . of ( createFunction . apply ( constructor , args ) ) ; }
tries to create the object using the given constructor