I met a problem this afternoon when test following souce snap:
Properties p = new Properties(); #1
p.put("smsc.adapter.driver.number", 2); #2
int driverNumbers = Integer.intValue(p.getProperty("smsc.adapter.driver.number")); #3
Yes, there is a Nullpointer Exception in line #3.
After review JDK source code, I just found Properties is a subclass of Hashtable (Damn it!).
java.util.Hashtable characters
- Cannot put null value
- Hashtable is Synchronized
For more details. please refer to (http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Hashtable.html).
java.util.Properties usage
- Properties.setProperty(String key, String value): only accept String value. Other data type should be convert to String before set property.
- Properties.getProperty(String key): it can only get Properties setted through Properties.setProperty(String key, String value).
PropertySet
PropertySet provide a persistence interface architecture to persiste Properties. It can be used to transmit parameters through different steps in distribute application.
We can find PropertySet usage in OsWorkflow.