G
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.
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.