Skip to content

Commit 1deb6b0

Browse files
committed
Apply "instanceof pattern matching" in SynthesizedMergedAnnotationInvocationHandler
1 parent 839cc5f commit 1deb6b0

File tree

1 file changed

+40
-40
lines changed

1 file changed

+40
-40
lines changed

spring-core/src/main/java/org/springframework/core/annotation/SynthesizedMergedAnnotationInvocationHandler.java

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -144,32 +144,32 @@ private Integer computeHashCode() {
144144
private int getValueHashCode(Object value) {
145145
// Use Arrays.hashCode(...) since Spring's ObjectUtils doesn't comply
146146
// with the requirements specified in Annotation#hashCode().
147-
if (value instanceof boolean[]) {
148-
return Arrays.hashCode((boolean[]) value);
147+
if (value instanceof boolean[] booleans) {
148+
return Arrays.hashCode(booleans);
149149
}
150-
if (value instanceof byte[]) {
151-
return Arrays.hashCode((byte[]) value);
150+
if (value instanceof byte[] bytes) {
151+
return Arrays.hashCode(bytes);
152152
}
153-
if (value instanceof char[]) {
154-
return Arrays.hashCode((char[]) value);
153+
if (value instanceof char[] chars) {
154+
return Arrays.hashCode(chars);
155155
}
156-
if (value instanceof double[]) {
157-
return Arrays.hashCode((double[]) value);
156+
if (value instanceof double[] doubles) {
157+
return Arrays.hashCode(doubles);
158158
}
159-
if (value instanceof float[]) {
160-
return Arrays.hashCode((float[]) value);
159+
if (value instanceof float[] floats) {
160+
return Arrays.hashCode(floats);
161161
}
162-
if (value instanceof int[]) {
163-
return Arrays.hashCode((int[]) value);
162+
if (value instanceof int[] ints) {
163+
return Arrays.hashCode(ints);
164164
}
165-
if (value instanceof long[]) {
166-
return Arrays.hashCode((long[]) value);
165+
if (value instanceof long[] longs) {
166+
return Arrays.hashCode(longs);
167167
}
168-
if (value instanceof short[]) {
169-
return Arrays.hashCode((short[]) value);
168+
if (value instanceof short[] shorts) {
169+
return Arrays.hashCode(shorts);
170170
}
171-
if (value instanceof Object[]) {
172-
return Arrays.hashCode((Object[]) value);
171+
if (value instanceof Object[] objects) {
172+
return Arrays.hashCode(objects);
173173
}
174174
return value.hashCode();
175175
}
@@ -195,14 +195,14 @@ private String annotationToString() {
195195
}
196196

197197
private String toString(Object value) {
198-
if (value instanceof String) {
199-
return '"' + value.toString() + '"';
198+
if (value instanceof String str) {
199+
return '"' + str + '"';
200200
}
201-
if (value instanceof Enum) {
202-
return ((Enum<?>) value).name();
201+
if (value instanceof Enum<?> e) {
202+
return e.name();
203203
}
204-
if (value instanceof Class) {
205-
return ((Class<?>) value).getName() + ".class";
204+
if (value instanceof Class<?> clazz) {
205+
return clazz.getName() + ".class";
206206
}
207207
if (value.getClass().isArray()) {
208208
StringBuilder builder = new StringBuilder("{");
@@ -239,29 +239,29 @@ private Object getAttributeValue(Method method) {
239239
* @param array the array to clone
240240
*/
241241
private Object cloneArray(Object array) {
242-
if (array instanceof boolean[]) {
243-
return ((boolean[]) array).clone();
242+
if (array instanceof boolean[] booleans) {
243+
return booleans.clone();
244244
}
245-
if (array instanceof byte[]) {
246-
return ((byte[]) array).clone();
245+
if (array instanceof byte[] bytes) {
246+
return bytes.clone();
247247
}
248-
if (array instanceof char[]) {
249-
return ((char[]) array).clone();
248+
if (array instanceof char[] chars) {
249+
return chars.clone();
250250
}
251-
if (array instanceof double[]) {
252-
return ((double[]) array).clone();
251+
if (array instanceof double[] doubles) {
252+
return doubles.clone();
253253
}
254-
if (array instanceof float[]) {
255-
return ((float[]) array).clone();
254+
if (array instanceof float[] floats) {
255+
return floats.clone();
256256
}
257-
if (array instanceof int[]) {
258-
return ((int[]) array).clone();
257+
if (array instanceof int[] ints) {
258+
return ints.clone();
259259
}
260-
if (array instanceof long[]) {
261-
return ((long[]) array).clone();
260+
if (array instanceof long[] longs) {
261+
return longs.clone();
262262
}
263-
if (array instanceof short[]) {
264-
return ((short[]) array).clone();
263+
if (array instanceof short[] shorts) {
264+
return shorts.clone();
265265
}
266266

267267
// else

0 commit comments

Comments
 (0)