List of usage examples for java.lang.reflect Field getName
public String getName()
From source file:Main.java
public static void main(String[] args) { Field[] fields = java.lang.Integer.class.getDeclaredFields(); for (int i = 0; i < fields.length; i++) { Field f = fields[i]; String name = f.getName(); System.out.println(name); }//from www .ja v a2 s .com }
From source file:Main.java
public static void main(String[] args) { Field[] fields = java.lang.Integer.class.getDeclaredFields(); for (int i = 0; i < fields.length; i++) { Field f = fields[i]; Class type = f.getType(); String name = f.getName(); System.out.print(Modifier.toString(f.getModifiers())); System.out.println(" " + type.getCanonicalName() + " " + name + ";"); }// ww w . ja v a 2 s . c o m }
From source file:Main.java
public static void main(String[] args) throws Exception { GetFields object = new GetFields(); Class clazz = object.getClass(); // Get all object fields including public, protected, package and private // access fields. Field[] fields = clazz.getDeclaredFields(); System.out.println("Number of fields = " + fields.length); for (Field field : fields) { System.out.println("Field name = " + field.getName()); System.out.println("Field type = " + field.getType().getName()); }/*from w w w . ja va 2s . co m*/ }
From source file:Main.java
public static void main(String[] args) throws Exception { GetFields object = new GetFields(); Class clazz = object.getClass(); // Get all object accessible public fields. Field[] fields = clazz.getFields(); System.out.println("Number of fields = " + fields.length); for (Field field : fields) { System.out.println("Field name = " + field.getName()); System.out.println("Field type = " + field.getType().getName()); }//w w w . j a v a2s. c o m Field field = clazz.getField("id"); System.out.println("Field name = " + field.getName()); System.out.println("Field type = " + field.getType().getName()); }
From source file:testReflection.java
public static void main(String[] args) { try {/*from w w w . j a v a2s . c o m*/ C c = new C(); Class klass = c.getClass(); Field[] fields = getAllFields(klass); for (Field field : fields) { System.out.println(field.getName()); } } catch (Throwable a_th) { a_th.printStackTrace(); } }
From source file:gov.nih.nci.cabig.caaers.tools.ObjectDump.java
public static void main(String[] args) { ObjectDump target = new ObjectDump(); Class cls = null;/*w ww.j a va 2s . c o m*/ Field[] fields; try { cls = Class.forName(target.getClass().getName()); } catch (ClassNotFoundException e) { e.printStackTrace(); } write("Class: " + target.getClass().getName() + "\n"); fields = cls.getFields(); for (int i = 0; i < fields.length; i++) { Field field = fields[i]; write("\tfield[" + (i + 1) + "]: " + field.getName() + "\r\n"); Type type = field.getType(); write(type.toString()); } }
From source file:DataBeanTest.java
public static void main(String[] args) { Class d = DataBean.class; Field fs[] = d.getFields();//from www . j av a 2s .c o m for (Field f : fs) { System.out.println(f); Annotation a = f.getAnnotation(DataField.class); if (a != null) { System.out.println(f.getName()); } } }
From source file:Main.java
public static void main(String[] argv) throws Exception { Class cls = java.lang.String.class; Method method = cls.getMethods()[0]; Field field = cls.getFields()[0]; Constructor constructor = cls.getConstructors()[0]; String name;/* w w w . ja v a 2s. c o m*/ name = cls.getName(); System.out.println(name); name = cls.getName() + "." + field.getName(); System.out.println(name); name = constructor.getName(); System.out.println(name); name = cls.getName() + "." + method.getName(); System.out.println(name); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Class cls = java.lang.String.class; Method method = cls.getMethods()[0]; Field field = cls.getFields()[0]; Constructor constructor = cls.getConstructors()[0]; String name;/*from www . jav a 2 s.com*/ name = cls.getName().substring(cls.getPackage().getName().length() + 1); System.out.println(name); name = field.getName(); System.out.println(name); name = constructor.getName().substring(cls.getPackage().getName().length() + 1); System.out.println(name); name = method.getName(); System.out.println(name); }
From source file:com.music.tools.InstrumentExtractor.java
public static void main(String[] args) { Map<Integer, String> instrumentNames = new HashMap<>(); Field[] fields = ProgramChanges.class.getDeclaredFields(); try {//from w ww . ja v a 2s.c o m for (Field field : fields) { Integer value = (Integer) field.get(null); if (!instrumentNames.containsKey(value)) { instrumentNames.put(value, StringUtils.capitalize(field.getName().toLowerCase()).replace('_', ' ')); } } } catch (IllegalArgumentException | IllegalAccessException e) { throw new IllegalStateException(e); } Score score = new Score(); Read.midi(score, "C:\\Users\\bozho\\Downloads\\7938.midi"); for (Part part : score.getPartArray()) { System.out.println(part.getChannel() + " : " + part.getInstrument() + ": " + instrumentNames.get(part.getInstrument())); } }