Properties, defaults not working

Discussion in 'Java' started by Guest, Sep 30, 2003.

  1. Guest

    Guest Guest

    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.
    Guest, Sep 30, 2003
    #1
    1. Advertising

  2. Hello

    <> wrote in message news:3f7965af$0$247$...
    >
    > 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"));


    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){
    > 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.
    >
    >


    WBR,
    Andrey Vakhnin
    Andrey S. Vakhnin, Sep 30, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Fox

    Changing VS.NET defaults

    Mark Fox, Jul 31, 2003, in forum: ASP .Net
    Replies:
    5
    Views:
    365
    Yan-Hong Huang[MSFT]
    Aug 4, 2003
  2. Lauchlan M
    Replies:
    2
    Views:
    494
    John Saunders
    Aug 17, 2003
  3. John A Grandy
    Replies:
    0
    Views:
    323
    John A Grandy
    Oct 16, 2003
  4. blues2use

    debian defaults not up-to-date

    blues2use, Jun 12, 2011, in forum: Python
    Replies:
    1
    Views:
    536
  5. Bernie Beattie

    Login Control not using skin defaults?

    Bernie Beattie, Aug 11, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    244
    Bernie Beattie
    Aug 11, 2006
Loading...

Share This Page