diff --git a/spring-context/src/main/java/org/springframework/jmx/export/assembler/AbstractConfigurableMBeanInfoAssembler.java b/spring-context/src/main/java/org/springframework/jmx/export/assembler/AbstractConfigurableMBeanInfoAssembler.java index 525a2743265..dba27a1205f 100644 --- a/spring-context/src/main/java/org/springframework/jmx/export/assembler/AbstractConfigurableMBeanInfoAssembler.java +++ b/spring-context/src/main/java/org/springframework/jmx/export/assembler/AbstractConfigurableMBeanInfoAssembler.java @@ -76,8 +76,7 @@ public abstract class AbstractConfigurableMBeanInfoAssembler extends AbstractRef if (mapValue instanceof ManagedNotification mn) { return new ModelMBeanNotificationInfo[] {JmxMetadataUtils.convertToModelMBeanNotificationInfo(mn)}; } - else if (mapValue instanceof Collection) { - Collection col = (Collection) mapValue; + else if (mapValue instanceof Collection col) { List result = new ArrayList<>(); for (Object colValue : col) { if (!(colValue instanceof ManagedNotification mn)) { diff --git a/spring-core/src/main/java/org/springframework/core/Conventions.java b/spring-core/src/main/java/org/springframework/core/Conventions.java index 70daea7b454..be3abc598a9 100644 --- a/spring-core/src/main/java/org/springframework/core/Conventions.java +++ b/spring-core/src/main/java/org/springframework/core/Conventions.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -70,8 +70,7 @@ public final class Conventions { valueClass = value.getClass().getComponentType(); pluralize = true; } - else if (value instanceof Collection) { - Collection collection = (Collection) value; + else if (value instanceof Collection collection) { if (collection.isEmpty()) { throw new IllegalArgumentException( "Cannot generate variable name for an empty Collection"); @@ -188,11 +187,10 @@ public final class Conventions { else if (Collection.class.isAssignableFrom(resolvedType)) { valueClass = ResolvableType.forMethodReturnType(method).asCollection().resolveGeneric(); if (valueClass == null) { - if (!(value instanceof Collection)) { + if (!(value instanceof Collection collection)) { throw new IllegalArgumentException("Cannot generate variable name " + "for non-typed Collection return type and a non-Collection value"); } - Collection collection = (Collection) value; if (collection.isEmpty()) { throw new IllegalArgumentException("Cannot generate variable name " + "for non-typed Collection return type and an empty Collection value"); diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/AbstractWebSocketMessage.java b/spring-websocket/src/main/java/org/springframework/web/socket/AbstractWebSocketMessage.java index b3a3b3ae635..cd9d187a92f 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/AbstractWebSocketMessage.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/AbstractWebSocketMessage.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -79,10 +79,9 @@ public abstract class AbstractWebSocketMessage implements WebSocketMessage if (this == other) { return true; } - if (!(other instanceof AbstractWebSocketMessage)) { + if (!(other instanceof AbstractWebSocketMessage otherMessage)) { return false; } - AbstractWebSocketMessage otherMessage = (AbstractWebSocketMessage) other; return ObjectUtils.nullSafeEquals(this.payload, otherMessage.payload); }