提交 7d23245d 编写于 作者: S smarks

7174936: several String methods claim to always create new String

Reviewed-by: dholmes, bchristi, alanb, lancea
上级 eeac871b
...@@ -123,7 +123,7 @@ public final class String ...@@ -123,7 +123,7 @@ public final class String
* Class String is special cased within the Serialization Stream Protocol. * Class String is special cased within the Serialization Stream Protocol.
* *
* A String instance is written into an ObjectOutputStream according to * A String instance is written into an ObjectOutputStream according to
* <a href="{@docroot}../platform/serialization/spec/output.html"> * <a href="{@docRoot}/../platform/serialization/spec/output.html">
* Object Serialization Specification, Section 6.2, "Stream Elements"</a> * Object Serialization Specification, Section 6.2, "Stream Elements"</a>
*/ */
private static final ObjectStreamField[] serialPersistentFields = private static final ObjectStreamField[] serialPersistentFields =
...@@ -1893,7 +1893,7 @@ public final class String ...@@ -1893,7 +1893,7 @@ public final class String
} }
/** /**
* Returns a new string that is a substring of this string. The * Returns a string that is a substring of this string. The
* substring begins with the character at the specified index and * substring begins with the character at the specified index and
* extends to the end of this string. <p> * extends to the end of this string. <p>
* Examples: * Examples:
...@@ -1921,7 +1921,7 @@ public final class String ...@@ -1921,7 +1921,7 @@ public final class String
} }
/** /**
* Returns a new string that is a substring of this string. The * Returns a string that is a substring of this string. The
* substring begins at the specified {@code beginIndex} and * substring begins at the specified {@code beginIndex} and
* extends to the character at index {@code endIndex - 1}. * extends to the character at index {@code endIndex - 1}.
* Thus the length of the substring is {@code endIndex-beginIndex}. * Thus the length of the substring is {@code endIndex-beginIndex}.
...@@ -1970,6 +1970,7 @@ public final class String ...@@ -1970,6 +1970,7 @@ public final class String
* <blockquote><pre> * <blockquote><pre>
* str.substring(begin,&nbsp;end)</pre></blockquote> * str.substring(begin,&nbsp;end)</pre></blockquote>
* *
* @apiNote
* This method is defined so that the {@code String} class can implement * This method is defined so that the {@code String} class can implement
* the {@link CharSequence} interface. * the {@link CharSequence} interface.
* *
...@@ -1993,8 +1994,8 @@ public final class String ...@@ -1993,8 +1994,8 @@ public final class String
* Concatenates the specified string to the end of this string. * Concatenates the specified string to the end of this string.
* <p> * <p>
* If the length of the argument string is {@code 0}, then this * If the length of the argument string is {@code 0}, then this
* {@code String} object is returned. Otherwise, a new * {@code String} object is returned. Otherwise, a
* {@code String} object is created, representing a character * {@code String} object is returned that represents a character
* sequence that is the concatenation of the character sequence * sequence that is the concatenation of the character sequence
* represented by this {@code String} object and the character * represented by this {@code String} object and the character
* sequence represented by the argument string.<p> * sequence represented by the argument string.<p>
...@@ -2021,13 +2022,13 @@ public final class String ...@@ -2021,13 +2022,13 @@ public final class String
} }
/** /**
* Returns a new string resulting from replacing all occurrences of * Returns a string resulting from replacing all occurrences of
* {@code oldChar} in this string with {@code newChar}. * {@code oldChar} in this string with {@code newChar}.
* <p> * <p>
* If the character {@code oldChar} does not occur in the * If the character {@code oldChar} does not occur in the
* character sequence represented by this {@code String} object, * character sequence represented by this {@code String} object,
* then a reference to this {@code String} object is returned. * then a reference to this {@code String} object is returned.
* Otherwise, a new {@code String} object is created that * Otherwise, a {@code String} object is returned that
* represents a character sequence identical to the character sequence * represents a character sequence identical to the character sequence
* represented by this {@code String} object, except that every * represented by this {@code String} object, except that every
* occurrence of {@code oldChar} is replaced by an occurrence * occurrence of {@code oldChar} is replaced by an occurrence
...@@ -2818,8 +2819,8 @@ public final class String ...@@ -2818,8 +2819,8 @@ public final class String
} }
/** /**
* Returns a copy of the string, with leading and trailing whitespace * Returns a string whose value is this string, with any leading and trailing
* omitted. * whitespace removed.
* <p> * <p>
* If this {@code String} object represents an empty character * If this {@code String} object represents an empty character
* sequence, or the first and last characters of character sequence * sequence, or the first and last characters of character sequence
...@@ -2828,15 +2829,15 @@ public final class String ...@@ -2828,15 +2829,15 @@ public final class String
* reference to this {@code String} object is returned. * reference to this {@code String} object is returned.
* <p> * <p>
* Otherwise, if there is no character with a code greater than * Otherwise, if there is no character with a code greater than
* {@code '\u005Cu0020'} in the string, then a new * {@code '\u005Cu0020'} in the string, then a
* {@code String} object representing an empty string is created * {@code String} object representing an empty string is
* and returned. * returned.
* <p> * <p>
* Otherwise, let <i>k</i> be the index of the first character in the * Otherwise, let <i>k</i> be the index of the first character in the
* string whose code is greater than {@code '\u005Cu0020'}, and let * string whose code is greater than {@code '\u005Cu0020'}, and let
* <i>m</i> be the index of the last character in the string whose code * <i>m</i> be the index of the last character in the string whose code
* is greater than {@code '\u005Cu0020'}. A new {@code String} * is greater than {@code '\u005Cu0020'}. A {@code String}
* object is created, representing the substring of this string that * object is returned, representing the substring of this string that
* begins with the character at index <i>k</i> and ends with the * begins with the character at index <i>k</i> and ends with the
* character at index <i>m</i>-that is, the result of * character at index <i>m</i>-that is, the result of
* {@code this.substring(k, m + 1)}. * {@code this.substring(k, m + 1)}.
...@@ -2844,7 +2845,7 @@ public final class String ...@@ -2844,7 +2845,7 @@ public final class String
* This method may be used to trim whitespace (as defined above) from * This method may be used to trim whitespace (as defined above) from
* the beginning and end of a string. * the beginning and end of a string.
* *
* @return A copy of this string with leading and trailing white * @return A string whose value is this string, with any leading and trailing white
* space removed, or this string if it has no leading or * space removed, or this string if it has no leading or
* trailing white space. * trailing white space.
*/ */
...@@ -2981,12 +2982,12 @@ public final class String ...@@ -2981,12 +2982,12 @@ public final class String
/** /**
* Returns the string representation of the {@code char} array * Returns the string representation of the {@code char} array
* argument. The contents of the character array are copied; subsequent * argument. The contents of the character array are copied; subsequent
* modification of the character array does not affect the newly * modification of the character array does not affect the returned
* created string. * string.
* *
* @param data a {@code char} array. * @param data the character array.
* @return a newly allocated string representing the same sequence of * @return a {@code String} that contains the characters of the
* characters contained in the character array argument. * character array.
*/ */
public static String valueOf(char data[]) { public static String valueOf(char data[]) {
return new String(data); return new String(data);
...@@ -3000,14 +3001,13 @@ public final class String ...@@ -3000,14 +3001,13 @@ public final class String
* character of the subarray. The {@code count} argument * character of the subarray. The {@code count} argument
* specifies the length of the subarray. The contents of the subarray * specifies the length of the subarray. The contents of the subarray
* are copied; subsequent modification of the character array does not * are copied; subsequent modification of the character array does not
* affect the newly created string. * affect the returned string.
* *
* @param data the character array. * @param data the character array.
* @param offset the initial offset into the value of the * @param offset initial offset of the subarray.
* {@code String}. * @param count length of the subarray.
* @param count the length of the value of the {@code String}. * @return a {@code String} that contains the characters of the
* @return a string representing the sequence of characters contained * specified subarray of the character array.
* in the subarray of the character array argument.
* @exception IndexOutOfBoundsException if {@code offset} is * @exception IndexOutOfBoundsException if {@code offset} is
* negative, or {@code count} is negative, or * negative, or {@code count} is negative, or
* {@code offset+count} is larger than * {@code offset+count} is larger than
...@@ -3018,23 +3018,24 @@ public final class String ...@@ -3018,23 +3018,24 @@ public final class String
} }
/** /**
* Returns a String that represents the character sequence in the * Equivalent to {@link #valueOf(char[], int, int)}.
* array specified.
* *
* @param data the character array. * @param data the character array.
* @param offset initial offset of the subarray. * @param offset initial offset of the subarray.
* @param count length of the subarray. * @param count length of the subarray.
* @return a {@code String} that contains the characters of the * @return a {@code String} that contains the characters of the
* specified subarray of the character array. * specified subarray of the character array.
* @exception IndexOutOfBoundsException if {@code offset} is
* negative, or {@code count} is negative, or
* {@code offset+count} is larger than
* {@code data.length}.
*/ */
public static String copyValueOf(char data[], int offset, int count) { public static String copyValueOf(char data[], int offset, int count) {
// All public String constructors now copy the data.
return new String(data, offset, count); return new String(data, offset, count);
} }
/** /**
* Returns a String that represents the character sequence in the * Equivalent to {@link #valueOf(char[])}.
* array specified.
* *
* @param data the character array. * @param data the character array.
* @return a {@code String} that contains the characters of the * @return a {@code String} that contains the characters of the
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册