Win a copy of liveProject: Protecting User Data with Spring Security and OAuth2 this week in the Spring forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Managing properties

 
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Properties are configuration values managed as key/value pairs. In each pair, the key and value are both String values

To manage properties, create instances of java.util.Properties.

Is one able to extend the use of this method to incorporate values that are integer, double or boolean ?

If so, please show an example of how

Bob M

 
Marshal
Posts: 72603
317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is nothing to stop you creating a properties class taking Integers or Booleans (capital I/B) as the “V”s in its map.
But changing the type of a preexisting map means your methods do not maintain the types they are handling nor returning, so they cannot be overridden versions of each other.The second example would require a map taking different types, a Map<String, Integer>.
A getProperty() method will be even harder to implement; you would have several override equivalent versions with different return types, and that won't compile either.
 
Bob Matthews
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I get the following error messages when compiling:-
                                                                                                     
The method getProperty(String, String) in the type Properties is not applicable for the arguments (String, boolean)
The method getProperty(String, String) in the type Properties is not applicable for the arguments (String, int)
The method getProperty(String, String) in the type Properties is not applicable for the arguments (String, double)

The original code used a method which is no longer available and I do not have a copy of its code

Can I add code to handle these situations ?
 
Marshal
Posts: 26521
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why not just convert your int/double/boolean properties to and from String as required? I.e. convert them to String to put them in the properties file, convert them from String when getting them from the properties file.

It's not as if that's a wild and crazy idea, we had to do that with Windows .ini files since about 55 BC.
 
Bob Matthews
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK

I had thought of doing just that

I am trying to come to terms with having many String variables, where the word String is misleading
 
Campbell Ritchie
Marshal
Posts: 72603
317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It has been like that ever since 54BC (“owing to the peculiar Roman method of counting”). It might be a bad idea to maintain all properties as text, but that is what they did in 54BC and it is now very difficult to change to different types. It behaves as a pre‑existing map, whose types you can't now change.
 
When I was younger I felt like a man trapped inside a woman’s body. Then I was born. My twin is a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic