Code example for Field

Methods: getGenericTypegetType

0
   
  public static void main(String... args) {
		try { 
		    Class<?> c = Class.forName(args[0]);
		    Field f = c.getField(args[1]);
		    System.out.format("Type: %s%n", f.getType());
		    System.out.format("GenericType: %s%n", f.getGenericType());
	 
	        // production code should handle these exceptions more gracefully 
		} catch (ClassNotFoundException x) {
		    x.printStackTrace();
		} catch (NoSuchFieldException x) {
		    x.printStackTrace();
		} 
  } 
} 
/* 
args:{java reflect.members.FieldSpy reflect.members.FieldSpy count} 
output: 
java.lang.NoSuchFieldException: count 
Stop searching for code, let great code find you!  Add Codota to your java IDE