Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2003

Tip: Looking for answers? Try searching our database.

Properties, defaults not working

Thread view: 
- 30 Sep 2003 12:14 GMT
Hi!

Can anyone explain why the JavaDoc on Properties says:

"A property list can contain another property list as its "defaults";
this second property list is searched if the property key is not found
in the original property list."

and:

public Properties(Properties defaults)
Creates an empty property list with the specified defaults.

But when I write the following:

import java.util.*;
import java.io.*;
public class PropTest{

      private Properties props = null;

      public PropTest(){

              // Set defaults
              Properties defaults = new Properties();
              defaults.setProperty("Test1", "Default value for Test1");

              // Create global properties with defaults
              props = new Properties(defaults);

              // Set property (same result as with
props.load(propfile))
              props.setProperty("Test2","New value for test2");

              System.out.println("Test1 : "+props.get("Test1"));
              System.out.println("Test2 : "+props.get("Test2"));
      }
      public static void main(String[] args){
              PropTest p = new PropTest();    
      }
}

I get the output:

Test1 : null
Test2 : New value for test2

where I would expect Test1 to yield: "Default value for Test1"

I am using java version 1.4.1_01_b01

Thanks in advance for any comments!

Best regards
Martin

PS: Since I am not using my own email to avoid spam, you can write
directly to my email (remove spaces!) martin.wittrup @ jubiimail.dk
if you prefer to send direct response.
Andrey S. Vakhnin - 30 Sep 2003 15:16 GMT
> Hi!
>
[quoted text clipped - 32 lines]
>                System.out.println("Test1 : "+props.get("Test1"));
>                System.out.println("Test2 : "+props.get("Test2"));

Try to use:
                System.out.println("Test1 : "+props.getProperty("Test1"));

Method get is inherited from HashTable, which doesn't know anything about
default properties :)

>        }
>        public static void main(String[] args){
[quoted text clipped - 19 lines]
> directly to my email (remove spaces!) martin.wittrup @ jubiimail.dk
> if you prefer to send direct response.

WBR,
Andrey Vakhnin


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.