Object getObjectFromConstantFields ( Class cls ) { Field [ ] fields = cls . getFields ( ) ; Object instance = null ; for ( Field field : fields ) { instance = getObjectFromConstantField ( cls , field ) ; if ( instance != null ) { break ; } } return instance ; }
If the class has not empty constructor look static field if it return instance