問題
讀取excel表格中的2個值并比較這2個值是否相等集峦。
使用RichTextString的equals()方法來比較,發(fā)現(xiàn)明明2個值相等,結(jié)果還是返回false希柿;debug了一下源碼浮创。
//OK lets do this in stages to return a quickly, first check the actual string
boolean eq = ((field_1_charCount == other.field_1_charCount)
&& (field_2_optionflags == other.field_2_optionflags)
&& field_3_string.equals(other.field_3_string));
if (!eq) return false;
發(fā)現(xiàn)在比較的時候忧吟,field_2_optionflags == other.field_2_optionflags這兩個不相等。
方法上面還有一行注釋(大概意思就是富文本很難進行比較)
/**
* Our handling of equals is inconsistent with compareTo. The trouble is because we don't truely understand
* rich text fields yet it's difficult to make a sound comparison.
*
* @param o The object to compare.
* @return true if the object is actually equal.
*/
說明富文本不單單比較的是內(nèi)容還比較格式類型斩披。之前開發(fā)的時候沒有注意到這點溜族,結(jié)果測試的時候讹俊,測出來了。
最后還是用toString()方法煌抒,轉(zhuǎn)成字符串來進行比較仍劈。