8342863: Use pattern matching for instanceof in equals methods of wrapper classes
Reviewed-by: rriggs
This commit is contained in:
parent
e64f0798be
commit
a21c558699
src/java.base/share/classes/java/lang
@ -255,8 +255,8 @@ public final class Boolean implements java.io.Serializable,
|
||||
* same value; {@code false} otherwise.
|
||||
*/
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Boolean) {
|
||||
return value == ((Boolean)obj).booleanValue();
|
||||
if (obj instanceof Boolean b) {
|
||||
return value == b.booleanValue();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -477,8 +477,8 @@ public final class Byte extends Number implements Comparable<Byte>, Constable {
|
||||
* {@code false} otherwise.
|
||||
*/
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Byte) {
|
||||
return value == ((Byte)obj).byteValue();
|
||||
if (obj instanceof Byte b) {
|
||||
return value == b.byteValue();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -9066,8 +9066,8 @@ class Character implements java.io.Serializable, Comparable<Character>, Constabl
|
||||
* {@code false} otherwise.
|
||||
*/
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Character) {
|
||||
return value == ((Character)obj).charValue();
|
||||
if (obj instanceof Character c) {
|
||||
return value == c.charValue();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -1257,9 +1257,8 @@ public final class Double extends Number
|
||||
* @jls 15.21.1 Numerical Equality Operators == and !=
|
||||
*/
|
||||
public boolean equals(Object obj) {
|
||||
return (obj instanceof Double)
|
||||
&& (doubleToLongBits(((Double)obj).value) ==
|
||||
doubleToLongBits(value));
|
||||
return (obj instanceof Double d) &&
|
||||
(doubleToLongBits(d.value) == doubleToLongBits(value));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -889,8 +889,8 @@ public final class Float extends Number
|
||||
* @jls 15.21.1 Numerical Equality Operators == and !=
|
||||
*/
|
||||
public boolean equals(Object obj) {
|
||||
return (obj instanceof Float)
|
||||
&& (floatToIntBits(((Float)obj).value) == floatToIntBits(value));
|
||||
return (obj instanceof Float f) &&
|
||||
(floatToIntBits(f.value) == floatToIntBits(value));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1147,8 +1147,8 @@ public final class Integer extends Number
|
||||
* {@code false} otherwise.
|
||||
*/
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Integer) {
|
||||
return value == ((Integer)obj).intValue();
|
||||
if (obj instanceof Integer i) {
|
||||
return value == i.intValue();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -1245,8 +1245,8 @@ public final class Long extends Number
|
||||
* {@code false} otherwise.
|
||||
*/
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Long) {
|
||||
return value == ((Long)obj).longValue();
|
||||
if (obj instanceof Long ell) {
|
||||
return value == ell.longValue();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -483,8 +483,8 @@ public final class Short extends Number implements Comparable<Short>, Constable
|
||||
* {@code false} otherwise.
|
||||
*/
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Short) {
|
||||
return value == ((Short)obj).shortValue();
|
||||
if (obj instanceof Short s) {
|
||||
return value == s.shortValue();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user