From 77832a6da905f63b75ffa5ee450b914f9b933230 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Mon, 9 Jan 2023 18:25:33 +0100 Subject: [PATCH] Apply "instanceof pattern matching" in HttpHeaders --- .../org/springframework/http/HttpHeaders.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/HttpHeaders.java b/spring-web/src/main/java/org/springframework/http/HttpHeaders.java index 83116cae22fe..fe0688004d4c 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpHeaders.java +++ b/spring-web/src/main/java/org/springframework/http/HttpHeaders.java @@ -1773,19 +1773,19 @@ public Set>> entrySet() { @Override - public boolean equals(@Nullable Object other) { - if (this == other) { + public boolean equals(@Nullable Object obj) { + if (this == obj) { return true; } - if (!(other instanceof HttpHeaders)) { + if (!(obj instanceof HttpHeaders other)) { return false; } - return unwrap(this).equals(unwrap((HttpHeaders) other)); + return unwrap(this).equals(unwrap(other)); } private static MultiValueMap unwrap(HttpHeaders headers) { - while (headers.headers instanceof HttpHeaders) { - headers = (HttpHeaders) headers.headers; + while (headers.headers instanceof HttpHeaders httpHeaders) { + headers = httpHeaders; } return headers.headers; } @@ -1810,8 +1810,8 @@ public String toString() { * @since 5.3 */ public static HttpHeaders readOnlyHttpHeaders(MultiValueMap headers) { - return (headers instanceof HttpHeaders ? - readOnlyHttpHeaders((HttpHeaders) headers) : new ReadOnlyHttpHeaders(headers)); + return (headers instanceof HttpHeaders httpHeaders ? readOnlyHttpHeaders(httpHeaders) : + new ReadOnlyHttpHeaders(headers)); } /**