substring(int)
substring(int, int)
subSequence(int, int)
toString()
in both StringBuffer and StringBuilder.
The specs of the corresponding methods in String were clarified by
An example where a new String object need not be created might be if the result of calling toString() were cached, so that subsequent calls to toString() might return the same String. Another example would be returning "" (the empty string literal) if a substring has zero length.
The subSequence() method is declared to return CharSequence, but in both StringBuilder and StringBuffer it is specified to behave identically to the substring() method, which returns a String. Thus subSequence() returns a String that has been upcast to CharSequence. Since String objects can be freely reused, the relaxation of the "new" requirement does apply to subSequence(). (It doesn't apply to CharBuffer, though, which specifically requires that it returns a new CharBuffer.)
- csr for
-
JDK-8350031 (spec str) StringBuffer and StringBuilder methods improperly require "new" String to be returned
-
- Closed
-
- duplicates
-
JDK-8332282 AbstractStringBuilder.toString spec needs amendments for empty strings
-
- Closed
-
- relates to
-
JDK-7174936 (spec str) several String methods claim to always create new String
-
- Closed
-
-
JDK-8028757 (spec str) CharSequence.subSequence improperly requires a "new" CharSequence be returned
-
- Closed
-
-
JDK-8187652 (spec str) clarify specs of String.replace, replaceFirst, replaceAll
-
- Open
-
-
JDK-8332282 AbstractStringBuilder.toString spec needs amendments for empty strings
-
- Closed
-
- links to
-
Commit(master) openjdk/jdk/08bc59da
-
Review(master) openjdk/jdk/23599