RichTextString的equals()方法

问题
读取excel表格中的2个值并比较这2个值是否相等。
使用RichTextString的equals()方法来比较,发现明明2个值相等,结果还是返回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;

发现在比较的时候,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.
*/

说明富文本不单单比较的是内容还比较格式类型。之前开发的时候没有注意到这点,结果测试的时候,测出来了。

最后还是用toString()方法,转成字符串来进行比较。

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容