From 1deb6b04b86888d716b3e1bf53245d21e424c3ee Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Tue, 8 Feb 2022 14:27:08 +0100 Subject: [PATCH] Apply "instanceof pattern matching" in SynthesizedMergedAnnotationInvocationHandler --- ...izedMergedAnnotationInvocationHandler.java | 80 +++++++++---------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/annotation/SynthesizedMergedAnnotationInvocationHandler.java b/spring-core/src/main/java/org/springframework/core/annotation/SynthesizedMergedAnnotationInvocationHandler.java index 6838dc3779..3d0ef51ab5 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/SynthesizedMergedAnnotationInvocationHandler.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/SynthesizedMergedAnnotationInvocationHandler.java @@ -144,32 +144,32 @@ final class SynthesizedMergedAnnotationInvocationHandler i private int getValueHashCode(Object value) { // Use Arrays.hashCode(...) since Spring's ObjectUtils doesn't comply // with the requirements specified in Annotation#hashCode(). - if (value instanceof boolean[]) { - return Arrays.hashCode((boolean[]) value); + if (value instanceof boolean[] booleans) { + return Arrays.hashCode(booleans); } - if (value instanceof byte[]) { - return Arrays.hashCode((byte[]) value); + if (value instanceof byte[] bytes) { + return Arrays.hashCode(bytes); } - if (value instanceof char[]) { - return Arrays.hashCode((char[]) value); + if (value instanceof char[] chars) { + return Arrays.hashCode(chars); } - if (value instanceof double[]) { - return Arrays.hashCode((double[]) value); + if (value instanceof double[] doubles) { + return Arrays.hashCode(doubles); } - if (value instanceof float[]) { - return Arrays.hashCode((float[]) value); + if (value instanceof float[] floats) { + return Arrays.hashCode(floats); } - if (value instanceof int[]) { - return Arrays.hashCode((int[]) value); + if (value instanceof int[] ints) { + return Arrays.hashCode(ints); } - if (value instanceof long[]) { - return Arrays.hashCode((long[]) value); + if (value instanceof long[] longs) { + return Arrays.hashCode(longs); } - if (value instanceof short[]) { - return Arrays.hashCode((short[]) value); + if (value instanceof short[] shorts) { + return Arrays.hashCode(shorts); } - if (value instanceof Object[]) { - return Arrays.hashCode((Object[]) value); + if (value instanceof Object[] objects) { + return Arrays.hashCode(objects); } return value.hashCode(); } @@ -195,14 +195,14 @@ final class SynthesizedMergedAnnotationInvocationHandler i } private String toString(Object value) { - if (value instanceof String) { - return '"' + value.toString() + '"'; + if (value instanceof String str) { + return '"' + str + '"'; } - if (value instanceof Enum) { - return ((Enum) value).name(); + if (value instanceof Enum e) { + return e.name(); } - if (value instanceof Class) { - return ((Class) value).getName() + ".class"; + if (value instanceof Class clazz) { + return clazz.getName() + ".class"; } if (value.getClass().isArray()) { StringBuilder builder = new StringBuilder("{"); @@ -239,29 +239,29 @@ final class SynthesizedMergedAnnotationInvocationHandler i * @param array the array to clone */ private Object cloneArray(Object array) { - if (array instanceof boolean[]) { - return ((boolean[]) array).clone(); + if (array instanceof boolean[] booleans) { + return booleans.clone(); } - if (array instanceof byte[]) { - return ((byte[]) array).clone(); + if (array instanceof byte[] bytes) { + return bytes.clone(); } - if (array instanceof char[]) { - return ((char[]) array).clone(); + if (array instanceof char[] chars) { + return chars.clone(); } - if (array instanceof double[]) { - return ((double[]) array).clone(); + if (array instanceof double[] doubles) { + return doubles.clone(); } - if (array instanceof float[]) { - return ((float[]) array).clone(); + if (array instanceof float[] floats) { + return floats.clone(); } - if (array instanceof int[]) { - return ((int[]) array).clone(); + if (array instanceof int[] ints) { + return ints.clone(); } - if (array instanceof long[]) { - return ((long[]) array).clone(); + if (array instanceof long[] longs) { + return longs.clone(); } - if (array instanceof short[]) { - return ((short[]) array).clone(); + if (array instanceof short[] shorts) { + return shorts.clone(); } // else