Recently I was working on a Java application which required certain settings to be saved and reloaded, such as window positions, user data, etc. I thought it would be a great idea to use a centralized object which could keep track of the settings as many of them are shared between objects. As I got to thinking about how I could implement this centralized class, I imagined an XML file being saved to the drive which I would parse using a SAX parser, manually picking out the fields I wanted, and overall taking a ton of work. Everytime I wanted to add a new setting it involved going into my Settings class and adding a field and some custom SAX parsing code.
However, I realized that there was a much better way to do things, and that's to take advantage of the default Java Serialization API. This automatically handles the transfer of a Java object over a stream, which in my case are file streams so I can save and load the class. I also realized that rather than trying to push for efficiency and having the code completely valid by compile time, I would switch to a runtime management type approach. This involved Using a simple HashMap which would match objects with string key identifiers.