再看看BeanUtils的靜態(類)方法populate是怎么處理的: // Loop through the property name/value pairs to be set Iterator names = properties.keySet().iterator(); while (names.hasNext()) {
// Identify the property name and value(s) to be assigned String name = (String) names.next(); if (name == null) { continue; } Object value = properties.get(name);
// Perform the assignment for this property setProperty(bean, name, value);
使用方法是: if (log.isInfoEnabled()) { log.Info("some information."); } Logging把消息分為6種級別,debug,error,fatal,info,trace,warn。比如,你想記錄一條消息,它只是為了給用戶一個警告,則可以使用warn。為什么在每個log.Info()前做一次判定呢?難道假如log級別不答應Info,log.Info()仍然能Info嗎?當然不是。它的作用是提高效率。
比如有個消息是計算前一萬個自然數的和(這種消息可能少見)。用直接log.Info() int sum=0; for(int i=0;i<10000;i++){ sum+=i; } log.Info("the sum of form 1 to 10000 is : "_sum); 假如log.Info是不答應的,那求10000個數的和就白求的。當然假如你的計算機很快或和高斯一樣聰明,直接log.Info()也每什么問題。