aspose file tools
The moose likes Java in General and the fly likes in the my book appears above, well Properties(); key, value , is it REQUIRED to be <String,String>? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "in the my book appears above, well Properties(); key, value , is it REQUIRED to be <String,String>? " Watch "in the my book appears above, well Properties(); key, value , is it REQUIRED to be <String,String>? " New topic
Author

in the my book appears above, well Properties(); key, value , is it REQUIRED to be <String,String>?

Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 397
table = new Properties();
// set properties
table.setProperty( "color", "blue" );
table.setProperty( "width", "200" );

in the my book appears above, well Properties(); key, value , is it REQUIRED to be <String,String>? or only key be String? or ...
Michael Angstadt
Ranch Hand

Joined: Jun 17, 2009
Posts: 272

Please UseAMeaningfulSubjectLine.

The Properties class only accepts Strings as keys and values.


SCJP 6 || SCWCD 5
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

Not quite. Due to some unexpected (at least to me) decision, when generics were introduced Sun decided to let Properties extend Hashtable<Object,Object>, not Hashtable<String,String>. This means that although setProperty only lets you use Strings, the put method still is available and lets you use any object for both key and value except null (since Hashtable does not allow null keys or values).

This class is just an example of bad OO in Sun's early classes. Properties should never have extended Hashtable but use one internally. Likewise, java.util.Stack never should have extended Vector but again use one internally. We'll have to live with that, at least in the case of Properties. Which, I repeat, should have extended Hashtable<String,String>, not Hashtable<Object,Object>. Anyone using a Properties object to store objects other than Strings is abusing the bad OO and should be punished by having to rework his code.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: in the my book appears above, well Properties(); key, value , is it REQUIRED to be <String,String>?
 
Similar Threads
How to access a properties file values in Spring 3?
Constants Class
Save properties
Adding Properties through a Property file
Print Properties