Prev: read html file into org.w3c.dom.html.htmldocument
Next: Best way to check if all elements in a List are unique
From: askmax on 1 Mar 2010 17:28 Hi, Can anyone please tell me how I would access a subclass members with reflection. So for example: public class MyTestClass { public class SourceObj { String mytest1; } String mytest1; int mytest2; long mytest3; List<String> mytest4 = new java.util.ArrayList<String>(); HashMap<String,String> mytest5 = new HashMap<String, String>(); SourceObj mytest6 = new SourceObj(); } I want to set the value of mytest6.mytest1 Thanks, Max
From: John B. Matthews on 1 Mar 2010 17:48 In article <a11ce6b9-8054-4ccf-ab30-9173b5a42ffc(a)f35g2000yqd.googlegroups.com>, askmax <askmax(a)gmail.com> wrote: > Can anyone please tell me how I would access a subclass members with > reflection. Have you looked at <http://java.sun.com/docs/books/tutorial/reflect/>? -- John B. Matthews trashgod at gmail dot com <http://sites.google.com/site/drjohnbmatthews>
From: Daniel Pitts on 1 Mar 2010 18:28 On 3/1/2010 2:28 PM, askmax wrote: > Hi, > > Can anyone please tell me how I would access a subclass members with > reflection. > So for example: > > public class MyTestClass > { > public class SourceObj > { > String mytest1; > } > > String mytest1; > int mytest2; > long mytest3; > List<String> mytest4 = new java.util.ArrayList<String>(); > HashMap<String,String> mytest5 = new HashMap<String, String>(); > SourceObj mytest6 = new SourceObj(); > } > > I want to set the value of mytest6.mytest1 > > Thanks, > Max mytest6.mytest1="Foo". -- Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
From: EJP on 4 Mar 2010 04:23
On 2/03/2010 9:28 AM, askmax wrote: > > Can anyone please tell me how I would access a subclass members with > reflection. > > I want to set the value of mytest6.mytest1 So go ahead. But mytest6 is a SourceObj, which isn't a subclass of anything except Object. What is your *actual* problem? |