Modifying toString method to cache in a thread-safe way per LANG-481

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@900015 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2010-01-16 19:50:33 +00:00
parent 01067903aa
commit 6913747d7d
1 changed files with 5 additions and 3 deletions

View File

@ -350,16 +350,18 @@ public final class Range<T> implements Serializable {
*/ */
@Override @Override
public String toString() { public String toString() {
if (toString == null) { String result = toString;
if (result == null) {
StringBuilder buf = new StringBuilder(32); StringBuilder buf = new StringBuilder(32);
buf.append("Range["); buf.append("Range[");
buf.append(this.minimum); buf.append(this.minimum);
buf.append(','); buf.append(',');
buf.append(this.maximum); buf.append(this.maximum);
buf.append(']'); buf.append(']');
toString = buf.toString(); result = buf.toString();
toString = result;
} }
return toString; return result;
} }
// Taken from Commons Collections - documentation removed as not a public class // Taken from Commons Collections - documentation removed as not a public class