Put the object into Java util. In properties

I'm trying to understand why I implemented Java util. Properties. It has two interfaces: getproperty / setproperty, which only accepts strings and / get accepts any object as a value The two interfaces seem to overlap, so you can use getproperty () to retrieve a string with put ()

There seems to be something wrong with this strange hybrid interface Placing an object that overrides the string property has the side effect of clearing the string value and generating null as the getproperty result Adding an integer or some other value with a simple string conversion may be misunderstood as an actual attribute value (but always empty as an attribute)

My question is: is there really a practical reason? Or do I suspect it's a half baked implementation?

Solution

Joshua Bloch explicitly mentioned this in effective Java

The text is in the context of using combination over inheritance He basically uses this as an example of using composition rather than inheritance If the property contains a map instead of an extended map, it can force string as the variable of the key and value

So the answer is: This is a supervision

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>