String.subSequence and CR#6924259: Remove offset and count fields from java.lang.String
Alan.Bateman at oracle.com
Mon Jun 25 11:20:59 UTC 2012
On 22/06/2012 23:15, Mike Duigou wrote:
> - The CharSequences returned by subSequence would follow only the general CharSequence rules for equals()/hashCode(). Any current usages of the result of subSequence for equals() or hashing, even though it's not advised, would break. We could add equals() and hashCode() implementations to the CharSequence returned but they would probably be expensive.
I think Jason's idea to use CharBuffer.wrap(...).asReadOnlyBuffer() is a
great idea too. However as you mention hashCode/equals then one thing to
remember is that they depend on the number of remaining elements. It
should be okay assuming that someone doesn't cast to a CharBuffer and
invokes a method that changes the position or limit but even so, you
won't get any caching of the hash code.
More information about the core-libs-dev