On occasion, as much as I try to avoid it, I do generate a fair amount of boilerplate code in my programming. I've been told that the Java Class object can be used to get around boilerplate code, but I don't currently see how.
When I say boilerplate code, I'm referring to the term used to refer to text that is reused again and again, with slight modification.
public Map<String, Boolean> loadBooleanTags(File in)
{
// Code that extracts boolean tags
}
Now, suppose, you then want to load int tags, where the files are in the exact same format, but you want the data structure to be a Map<String, Integer>
. The only way I can think of handling this is like so:
public Map<String, Integer> loadIntegerTags(File in)
{
// Code that extracts integer tags
}
Essentially, I copy and past the boolean method, but I make it parse an Integer instead. What are some better ways to handle this? Ideally, I'd like to have one method that outputs a map with the correct generics.