`
george.gu
  • 浏览: 74399 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

java.util.Properties: a subclass of java.util.Hashtable

 
阅读更多

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.
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics