public static String [ ] getNames ( Object object ) { if ( object == null ) { return null ; } Class < ? extends Object > klass = object . getClass ( ) ; Field [ ] fields = klass . getFields ( ) ; int length = fields . length ; if ( length == 0 ) { return null ; } String [ ] names = new String [ length ] ; for ( int i = 0 ; i < length ; i += 1 ) { names [ i ] = fields [ i ] . getName ( ) ; } return names ; }
Get an array of field names from an Object .