Apply "instanceof pattern matching" in additional locations

Closes gh-27696
This commit is contained in:
liuzhifei 2021-11-18 20:13:13 +08:00 committed by Sam Brannen
parent 6555d3b42d
commit 7021eb5bb1
3 changed files with 6 additions and 10 deletions

View File

@ -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<ModelMBeanNotificationInfo> result = new ArrayList<>();
for (Object colValue : col) {
if (!(colValue instanceof ManagedNotification mn)) {

View File

@ -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");

View File

@ -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<T> implements WebSocketMessage<T>
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);
}