Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes Reset instances of a class and initialize again. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Reset instances of a class and initialize again." Watch "Reset instances of a class and initialize again." New topic
Author

Reset instances of a class and initialize again.

Tejeshwar Reddy
Greenhorn

Joined: Oct 08, 2009
Posts: 2
Hi,

I have an XML which i am using as a source for initializing a class in my project.

During the course of execution of the project I am creating instances of this class and making use of them. However I have one module where we can edit the contents of that source XML and save it. So after the saving of the XML, I am looking to reset the instances of the class which were created before and initialize them again with the new data from the XML.

This sounds like a basic question, but i am unable to figure out on how to reset instances of a class and initialize them again. Would be great if I can get some help on this.

Thanks.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

How did you initialize them at the first place ? Using reflection ? Using a constructor with parameters ?


[My Blog]
All roads lead to JavaRanch
Tejeshwar Reddy
Greenhorn

Joined: Oct 08, 2009
Posts: 2
Christophe Verré wrote:How did you initialize them at the first place ? Using reflection ? Using a constructor with parameters ?


I have used a constructor to initialize them.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

If you make a public method which initializes the instance variables, you can call it again to reinitialize your variables.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Reset instances of a class and initialize again.