Reflection accessing subclass

  • Follow


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
0
Reply askmax (2) 3/1/2010 10:28:05 PM

In article 
<a11ce6b9-8054-4ccf-ab30-9173b5a42ffc@f35g2000yqd.googlegroups.com>,
 askmax <askmax@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>
0
Reply John 3/1/2010 10:48:29 PM


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/>
0
Reply Daniel 3/1/2010 11:28:54 PM

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?
0
Reply EJP 3/4/2010 9:23:48 AM

3 Replies
195 Views

(page loaded in 0.086 seconds)


Reply: