Skip to content

Commit fe2ae8e

Browse files
author
Eamonn McManus
committedDec 8, 2021
8276904: Optional.toString() is unnecessarily expensive
Reviewed-by: rriggs, smarks
1 parent 6e7b7f3 commit fe2ae8e

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed
 

‎src/java.base/share/classes/java/util/Optional.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ public int hashCode() {
454454
@Override
455455
public String toString() {
456456
return value != null
457-
? String.format("Optional[%s]", value)
457+
? ("Optional[" + value + "]")
458458
: "Optional.empty";
459459
}
460460
}

‎src/java.base/share/classes/java/util/OptionalDouble.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ public int hashCode() {
328328
@Override
329329
public String toString() {
330330
return isPresent
331-
? String.format("OptionalDouble[%s]", value)
331+
? ("OptionalDouble[" + value + "]")
332332
: "OptionalDouble.empty";
333333
}
334334
}

‎src/java.base/share/classes/java/util/OptionalInt.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ public int hashCode() {
326326
@Override
327327
public String toString() {
328328
return isPresent
329-
? String.format("OptionalInt[%s]", value)
329+
? ("OptionalInt[" + value + "]")
330330
: "OptionalInt.empty";
331331
}
332332
}

‎src/java.base/share/classes/java/util/OptionalLong.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ public int hashCode() {
326326
@Override
327327
public String toString() {
328328
return isPresent
329-
? String.format("OptionalLong[%s]", value)
329+
? ("OptionalLong[" + value + "]")
330330
: "OptionalLong.empty";
331331
}
332332
}

0 commit comments

Comments
 (0)
Please sign in to comment.