On 10/29/2015 01:36 PM, Pavel Rappo wrote: >> On 29 Oct 2015, at 00:48, Aleksey Shipilev <aleksey.shipi...@oracle.com> >> wrote: >> Doesn't that break when CharSequence implementation is mutable? >> E.g. with StringBuilder, you cannot return "this" when "end == >> StringBuilder.length()" at the time of .subSequence() call. > > True. This trick cannot be used in cases where CharSequence is able to change > its length. (As far as I understand, possible changes in contents are ok.)
While Javadoc appears silent on this front, the expectation seems to be that .subSequence returns the "detached" subsequence. See spec change here: https://bugs.openjdk.java.net/browse/JDK-8028757 So, I think this trick works only for the completely immutable CharSequences, which apparently includes only Strings. And, AFAIU from the code, String already returns "this" in cases like these? Thanks, -Aleksey P.S. I think it would be evil to turn subSequence into the forwarding view. These were considered before: http://mail.openjdk.java.net/pipermail/core-libs-dev/2014-July/027838.html