Results 1 to 1 of 1
-
Object Reflection: Getting field value
Java Code:import java.awt.Rectangle; import java.lang.reflect.Field; public class SampleGet { public static void main(String[] args) { Rectangle r = new Rectangle(100, 325); printHeight(r); } static void printHeight(Rectangle r) { Field heightField; Integer heightValue; Class c = r.getClass(); try { heightField = c.getField("height"); heightValue = (Integer) heightField.get(r); System.out.println("Height: " + heightValue.toString()); } catch (NoSuchFieldException e) { System.out.println(e); } catch (SecurityException e) { System.out.println(e); } catch (IllegalAccessException e) { System.out.println(e); } } }"The sole cause of man’s unhappiness is that he does not know how to stay quietly in his room." - Blaise Pascal
Similar Threads
-
Operator < cannot be applied to java.lang.Object, Object
By Albert in forum Advanced JavaReplies: 2Last Post: 11-26-2010, 02:12 AM -
Class Reflection: Finding field infomation
By Java Tip in forum java.langReplies: 0Last Post: 04-23-2008, 08:09 PM -
Array Reflection: Multi Array Reflection
By Java Tip in forum java.langReplies: 0Last Post: 04-23-2008, 08:08 PM -
[SOLVED] If a object equals another object, do they contain the same data?
By bobleny in forum New To JavaReplies: 1Last Post: 04-17-2008, 10:10 PM -
Getting class field information using Reflection
By Java Tip in forum Java TipReplies: 0Last Post: 01-24-2008, 03:20 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks