I would like to use the following code from this question in order to sort Properties alphabetically:
Properties tmp = new Properties() {
@Override
public synchronized Enumeration<Object> keys() {
return Collections.enumeration(new TreeSet<Object>(super.keySet()));
}
};
However, instead of instantiating a Properties object and every time indicating that I want it to be alphabetical, how could I make a class that inherits Properties, for the sole purpose of explicitly overriding this method?
public class MyProperties extends Properties
{
@Override
public synchronized Enumeration<Object> keys() {
return Collections.enumeration(new TreeSet<Object>(super.keySet()));
}
}
This is in hopes of being able to do this:
MyProperties p = new MyProperties();
... and have it work exactly like a Properties object whose keys are sorted!
Somehow I don't feel this is that easy, is it? Do I need to do things like call the super's constructor? It's just a little unclear to me but I have a feeling it's possible to do. I'd rather not override a method every time I make a Properties object!
Thanks!