I ran across some confusing functionality with UIDefaults the other night. Let's see if anyone agrees with me...
The UIDefaults object associated with look and feels in Swing extends Hashtable and holds mappings for look and feel related properties. You'll find things like icons, colors. fonts, etc. Adding to this complexity is the fact that there are actually three sets of UIDefaults user, look and feel, and system. Because of this when you call
UIManager.getDefaults()
it says you are getting a plain UIDefaults object but you are not. Instead you get this strange MultiUIDefaults object that extends UIDefaults. It basically wraps the three sets of objects and looks through them all on a get request for a property starting with the user set. All of this is well and good. The MultiUIDefaults object provides custom implementations of standard methods like get(), size(), clear(), and remove(). Now on to my strange fact for the day. I'm writing a UIDefaults viewer for the book and wanted to iterate over all the properties. So logically I call
uiDefaults.keySet().iterator()
However, strangely my table only has about 5 properties in it. I knew that wasn't right. Turns out that MultiUIDefaults implements keys() which returns and Enumeration but not keySet(). Without looking at the source I would have never known this. When you extend a class should you not try to keep the meaning/spirit of its methods consistent with the parent? I really don't think I'm asking too much here.