gpt4 book ai didi

java - CharSequence equals() 不能正常工作

转载 作者:行者123 更新时间:2023-11-30 06:52:06 24 4
gpt4 key购买 nike

有这个代码:

if (cs.equals(keywordUnderProcess)) {

} else {

}

cskeywordUnderProcess 都是CharSequence,值为star,但else 情况下会执行。为什么? equals 检查值,不是吗?

enter image description here

enter image description here

最佳答案

如果您阅读 CharSequence 的 javadoc 页面接口(interface),它表示 equals 的行为未定义:

This interface does not refine the general contracts of the equals and hashCode methods. The result of comparing two objects that implement CharSequence is therefore, in general, undefined. Each object may be implemented by a different class, and there is no guarantee that each class will be capable of testing its instances for equality with those of the other. It is therefore inappropriate to use arbitrary CharSequence instances as elements in a set or as keys in a map.

关于java - CharSequence equals() 不能正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39541233/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com