Retreving the Class Objects at runtime using reflection

I'm using reflection to get the classes at runtime. Can any one suggest how to get the objects associated with that particular class.

For example, i have a class S1 and the objects associated with this class are X1 and X2.

I'm able to get the class name (i.e S1) using reflection.

Is there any method that will return me the objects (X1, X2) associated with this class.

Thanks

Murali

[423 byte] By [muralikrishna24a] at [2007-10-2 21:29:42]
# 1

You can either use like

Class theClass = YouClass.clss

then object x1 can be created like

x1 = Class.forName(theClass .getNameI())

you can similarly create tthe object also you can use

x1 = theClass.newInstance()

provided the defualt constructor should not expect any thing as argument for

intialising the class

tigerxxa at 2007-7-14 0:42:51 > top of Java-index,Core,Core APIs...
# 2

I have class S1 with some setter and getter methods.

I have created two objects X1 and X2 and using these objects i have called the setter methods.

Now during runtime i get the class name (S1) using reflection, and now i have to call the getter methods using the same objects (X1, X2).

Is there any way to retreive these objects (X1 and X2) of this class so that getter methods in that class can be accessed.

Thanks

Murali

muralikrishna24a at 2007-7-14 0:42:51 > top of Java-index,Core,Core APIs...
# 3
Check out reflection.
BIJ001a at 2007-7-14 0:42:51 > top of Java-index,Core,Core APIs...
# 4

If I understand right, you want to be able to get every instance of a class that has been created in your virtual machine. Can't do that with reflection. You could create a mechanism yourself with, say, a static collection and a constructor that adds the new instance to the collection as soon as it is created.

Updownquarka at 2007-7-14 0:42:51 > top of Java-index,Core,Core APIs...
# 5

> If I understand right, you want to be able to get

> every instance of a class that has been created in

> your virtual machine. Can't do that with reflection.

> You could create a mechanism yourself with, say, a

> static collection and a constructor that adds the

> new instance to the collection as soon as it is

> created.

Probably look into JVMPI for that.

_dnoyeBa at 2007-7-14 0:42:52 > top of Java-index,Core,Core APIs...