• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ...
 
Ranch Hand
Posts: 282
Eclipse IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseAMeaningfulSubjectLine.

The Properties class only accepts Strings as keys and values.

 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic