diff --git a/src/java.base/share/classes/java/net/HttpConnectSocketImpl.java b/src/java.base/share/classes/java/net/HttpConnectSocketImpl.java
index b06254699d597..0f5ca35115c36 100644
--- a/src/java.base/share/classes/java/net/HttpConnectSocketImpl.java
+++ b/src/java.base/share/classes/java/net/HttpConnectSocketImpl.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2021, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -80,10 +80,9 @@ public Void run() {
         super(delegate);
         this.socket = socket;
         SocketAddress a = proxy.address();
-        if ( !(a instanceof InetSocketAddress) )
+        if ( !(a instanceof InetSocketAddress ad) )
             throw new IllegalArgumentException("Unsupported address type");
 
-        InetSocketAddress ad = (InetSocketAddress) a;
         server = ad.getHostString();
         port = ad.getPort();
     }
diff --git a/src/java.base/share/classes/java/net/HttpCookie.java b/src/java.base/share/classes/java/net/HttpCookie.java
index eff638e2e021c..74c1c6dc69337 100644
--- a/src/java.base/share/classes/java/net/HttpCookie.java
+++ b/src/java.base/share/classes/java/net/HttpCookie.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -715,9 +715,8 @@ public String toString() {
     public boolean equals(Object obj) {
         if (obj == this)
             return true;
-        if (!(obj instanceof HttpCookie))
+        if (!(obj instanceof HttpCookie other))
             return false;
-        HttpCookie other = (HttpCookie)obj;
 
         // One http cookie is equal to another cookie (RFC 2965 sec. 3.3.3) if:
         //   1. they come from same domain (case-insensitive),
diff --git a/src/java.base/share/classes/java/net/Inet6Address.java b/src/java.base/share/classes/java/net/Inet6Address.java
index 26e6661e053bb..493696888410b 100644
--- a/src/java.base/share/classes/java/net/Inet6Address.java
+++ b/src/java.base/share/classes/java/net/Inet6Address.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -262,10 +262,9 @@ String getHostAddress() {
         }
 
         public boolean equals(Object o) {
-            if (! (o instanceof Inet6AddressHolder)) {
+            if (!(o instanceof Inet6AddressHolder that)) {
                 return false;
             }
-            Inet6AddressHolder that = (Inet6AddressHolder)o;
 
             return Arrays.equals(this.ipaddress, that.ipaddress);
         }
@@ -525,10 +524,9 @@ private static int deriveNumericScope (byte[] thisAddr, NetworkInterface ifc) th
         Enumeration<InetAddress> addresses = ifc.getInetAddresses();
         while (addresses.hasMoreElements()) {
             InetAddress addr = addresses.nextElement();
-            if (!(addr instanceof Inet6Address)) {
+            if (!(addr instanceof Inet6Address ia6_addr)) {
                 continue;
             }
-            Inet6Address ia6_addr = (Inet6Address)addr;
             /* check if site or link local prefixes match */
             if (!isDifferentLocalAddressType(thisAddr, ia6_addr.getAddress())){
                 /* type not the same, so carry on searching */
diff --git a/src/java.base/share/classes/java/net/InterfaceAddress.java b/src/java.base/share/classes/java/net/InterfaceAddress.java
index cc22970882a84..f5b76ec9f90ce 100644
--- a/src/java.base/share/classes/java/net/InterfaceAddress.java
+++ b/src/java.base/share/classes/java/net/InterfaceAddress.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -101,17 +101,10 @@ public short getNetworkPrefixLength() {
      * @see     java.net.InterfaceAddress#hashCode()
      */
     public boolean equals(Object obj) {
-        if (obj instanceof InterfaceAddress) {
-            InterfaceAddress cmp = (InterfaceAddress) obj;
-
-            if (Objects.equals(address, cmp.address) &&
+        return obj instanceof InterfaceAddress cmp &&
+                Objects.equals(address, cmp.address) &&
                 Objects.equals(broadcast, cmp.broadcast) &&
-                maskLength == cmp.maskLength)
-            {
-                return true;
-            }
-        }
-        return false;
+                maskLength == cmp.maskLength;
     }
 
     /**
diff --git a/src/java.base/share/classes/java/net/NetMulticastSocket.java b/src/java.base/share/classes/java/net/NetMulticastSocket.java
index 86969a698daec..79a902735d04e 100644
--- a/src/java.base/share/classes/java/net/NetMulticastSocket.java
+++ b/src/java.base/share/classes/java/net/NetMulticastSocket.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1995, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2021, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -216,9 +216,8 @@ public synchronized void bind(SocketAddress addr) throws SocketException {
             throw new SocketException("already bound");
         if (addr == null)
             addr = new InetSocketAddress(0);
-        if (!(addr instanceof InetSocketAddress))
+        if (!(addr instanceof InetSocketAddress epoint))
             throw new IllegalArgumentException("Unsupported address type!");
-        InetSocketAddress epoint = (InetSocketAddress) addr;
         if (epoint.isUnresolved())
             throw new SocketException("Unresolved address");
         InetAddress iaddr = epoint.getAddress();
@@ -259,9 +258,8 @@ public void connect(InetAddress address, int port) {
     public void connect(SocketAddress addr) throws SocketException {
         if (addr == null)
             throw new IllegalArgumentException("Address can't be null");
-        if (!(addr instanceof InetSocketAddress))
+        if (!(addr instanceof InetSocketAddress epoint))
             throw new IllegalArgumentException("Unsupported address type");
-        InetSocketAddress epoint = (InetSocketAddress) addr;
         if (epoint.isUnresolved())
             throw new SocketException("Unresolved address");
         connectInternal(epoint.getAddress(), epoint.getPort());
diff --git a/src/java.base/share/classes/java/net/NetworkInterface.java b/src/java.base/share/classes/java/net/NetworkInterface.java
index 1668ddbf347e4..e463f35b50848 100644
--- a/src/java.base/share/classes/java/net/NetworkInterface.java
+++ b/src/java.base/share/classes/java/net/NetworkInterface.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -590,10 +590,9 @@ public boolean isVirtual() {
      * @see     java.net.InetAddress#getAddress()
      */
     public boolean equals(Object obj) {
-        if (!(obj instanceof NetworkInterface)) {
+        if (!(obj instanceof NetworkInterface that)) {
             return false;
         }
-        NetworkInterface that = (NetworkInterface)obj;
         if (this.name != null ) {
             if (!this.name.equals(that.name)) {
                 return false;
diff --git a/src/java.base/share/classes/java/net/ServerSocket.java b/src/java.base/share/classes/java/net/ServerSocket.java
index 30574780f14aa..b7e6d07495bfa 100644
--- a/src/java.base/share/classes/java/net/ServerSocket.java
+++ b/src/java.base/share/classes/java/net/ServerSocket.java
@@ -373,9 +373,8 @@ public void bind(SocketAddress endpoint, int backlog) throws IOException {
             throw new SocketException("Already bound");
         if (endpoint == null)
             endpoint = new InetSocketAddress(0);
-        if (!(endpoint instanceof InetSocketAddress))
+        if (!(endpoint instanceof InetSocketAddress epoint))
             throw new IllegalArgumentException("Unsupported address type");
-        InetSocketAddress epoint = (InetSocketAddress) endpoint;
         if (epoint.isUnresolved())
             throw new SocketException("Unresolved address");
         if (backlog < 1)
diff --git a/src/java.base/share/classes/java/net/Socket.java b/src/java.base/share/classes/java/net/Socket.java
index 8250997894740..7ee552c20636b 100644
--- a/src/java.base/share/classes/java/net/Socket.java
+++ b/src/java.base/share/classes/java/net/Socket.java
@@ -611,10 +611,9 @@ public void connect(SocketAddress endpoint, int timeout) throws IOException {
         if (isConnected())
             throw new SocketException("already connected");
 
-        if (!(endpoint instanceof InetSocketAddress))
+        if (!(endpoint instanceof InetSocketAddress epoint))
             throw new IllegalArgumentException("Unsupported address type");
 
-        InetSocketAddress epoint = (InetSocketAddress) endpoint;
         InetAddress addr = epoint.getAddress ();
         int port = epoint.getPort();
         checkAddress(addr, "connect");
diff --git a/src/java.base/share/classes/java/net/SocketPermission.java b/src/java.base/share/classes/java/net/SocketPermission.java
index f7abe4e1b2204..de1363bba7388 100644
--- a/src/java.base/share/classes/java/net/SocketPermission.java
+++ b/src/java.base/share/classes/java/net/SocketPermission.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -860,14 +860,12 @@ void getIP()
     public boolean implies(Permission p) {
         int i,j;
 
-        if (!(p instanceof SocketPermission))
+        if (!(p instanceof SocketPermission that))
             return false;
 
         if (p == this)
             return true;
 
-        SocketPermission that = (SocketPermission) p;
-
         return ((this.mask & that.mask) == that.mask) &&
                                         impliesIgnoreMask(that);
     }
@@ -1040,11 +1038,9 @@ public boolean equals(Object obj) {
         if (obj == this)
             return true;
 
-        if (! (obj instanceof SocketPermission))
+        if (! (obj instanceof SocketPermission that))
             return false;
 
-        SocketPermission that = (SocketPermission) obj;
-
         //this is (overly?) complex!!!
 
         // check the mask first
@@ -1379,15 +1375,13 @@ public SocketPermissionCollection() {
      */
     @Override
     public void add(Permission permission) {
-        if (! (permission instanceof SocketPermission))
+        if (! (permission instanceof SocketPermission sp))
             throw new IllegalArgumentException("invalid permission: "+
                                                permission);
         if (isReadOnly())
             throw new SecurityException(
                 "attempt to add a Permission to a readonly PermissionCollection");
 
-        SocketPermission sp = (SocketPermission)permission;
-
         // Add permission to map if it is absent, or replace with new
         // permission if applicable. NOTE: cannot use lambda for
         // remappingFunction parameter until JDK-8076596 is fixed.
@@ -1426,11 +1420,9 @@ public SocketPermission apply(SocketPermission existingVal,
     @Override
     public boolean implies(Permission permission)
     {
-        if (! (permission instanceof SocketPermission))
+        if (! (permission instanceof SocketPermission np))
                 return false;
 
-        SocketPermission np = (SocketPermission) permission;
-
         int desired = np.getMask();
         int effective = 0;
         int needed = desired;
diff --git a/src/java.base/share/classes/java/net/SocksSocketImpl.java b/src/java.base/share/classes/java/net/SocksSocketImpl.java
index 88e6f0f612909..8337eeb619ffd 100644
--- a/src/java.base/share/classes/java/net/SocksSocketImpl.java
+++ b/src/java.base/share/classes/java/net/SocksSocketImpl.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -57,8 +57,7 @@ class SocksSocketImpl extends DelegatingSocketImpl implements SocksConsts {
     SocksSocketImpl(Proxy proxy, SocketImpl delegate) {
         super(delegate);
         SocketAddress a = proxy.address();
-        if (a instanceof InetSocketAddress) {
-            InetSocketAddress ad = (InetSocketAddress) a;
+        if (a instanceof InetSocketAddress ad) {
             // Use getHostString() to avoid reverse lookups
             server = ad.getHostString();
             serverPort = ad.getPort();
diff --git a/src/java.base/share/classes/java/net/URI.java b/src/java.base/share/classes/java/net/URI.java
index 92bdf73cf04fc..7248c8f0e154e 100644
--- a/src/java.base/share/classes/java/net/URI.java
+++ b/src/java.base/share/classes/java/net/URI.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -1501,9 +1501,8 @@ public String getFragment() {
     public boolean equals(Object ob) {
         if (ob == this)
             return true;
-        if (!(ob instanceof URI))
+        if (!(ob instanceof URI that))
             return false;
-        URI that = (URI)ob;
         if (this.isOpaque() != that.isOpaque()) return false;
         if (!equalIgnoringCase(this.scheme, that.scheme)) return false;
         if (!equal(this.fragment, that.fragment)) return false;
diff --git a/src/java.base/share/classes/java/net/URL.java b/src/java.base/share/classes/java/net/URL.java
index 498d573101704..b6fd85e864631 100644
--- a/src/java.base/share/classes/java/net/URL.java
+++ b/src/java.base/share/classes/java/net/URL.java
@@ -972,9 +972,8 @@ public String getRef() {
      *          {@code false} otherwise.
      */
     public boolean equals(Object obj) {
-        if (!(obj instanceof URL))
+        if (!(obj instanceof URL u2))
             return false;
-        URL u2 = (URL)obj;
 
         return handler.equals(this, u2);
     }
diff --git a/src/java.base/share/classes/java/net/URLClassLoader.java b/src/java.base/share/classes/java/net/URLClassLoader.java
index e15669b43b8c1..37691f666ed81 100644
--- a/src/java.base/share/classes/java/net/URLClassLoader.java
+++ b/src/java.base/share/classes/java/net/URLClassLoader.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -288,8 +288,7 @@ public InputStream getResourceAsStream(String name) {
             }
             URLConnection urlc = url.openConnection();
             InputStream is = urlc.getInputStream();
-            if (urlc instanceof JarURLConnection) {
-                JarURLConnection juc = (JarURLConnection)urlc;
+            if (urlc instanceof JarURLConnection juc) {
                 JarFile jar = juc.getJarFile();
                 synchronized (closeables) {
                     if (!closeables.containsKey(jar)) {
diff --git a/src/java.base/share/classes/java/net/URLPermission.java b/src/java.base/share/classes/java/net/URLPermission.java
index f351a958179f3..0cd818ef64b83 100644
--- a/src/java.base/share/classes/java/net/URLPermission.java
+++ b/src/java.base/share/classes/java/net/URLPermission.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -298,12 +298,10 @@ public String getActions() {
      * </table>
      */
     public boolean implies(Permission p) {
-        if (! (p instanceof URLPermission)) {
+        if (! (p instanceof URLPermission that)) {
             return false;
         }
 
-        URLPermission that = (URLPermission)p;
-
         if (this.methods.isEmpty() && !that.methods.isEmpty()) {
             return false;
         }
@@ -374,10 +372,9 @@ public boolean implies(Permission p) {
      * and p's url equals this's url.  Returns false otherwise.
      */
     public boolean equals(Object p) {
-        if (!(p instanceof URLPermission)) {
+        if (!(p instanceof URLPermission that)) {
             return false;
         }
-        URLPermission that = (URLPermission)p;
         if (!this.scheme.equals(that.scheme)) {
             return false;
         }
diff --git a/src/java.base/share/classes/java/net/UnixDomainSocketAddress.java b/src/java.base/share/classes/java/net/UnixDomainSocketAddress.java
index 9b5faa3ea97d8..f3ead246be118 100644
--- a/src/java.base/share/classes/java/net/UnixDomainSocketAddress.java
+++ b/src/java.base/share/classes/java/net/UnixDomainSocketAddress.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -194,9 +194,8 @@ public int hashCode() {
      */
     @Override
     public boolean equals(Object o) {
-        if (!(o instanceof UnixDomainSocketAddress))
+        if (!(o instanceof UnixDomainSocketAddress that))
             return false;
-        UnixDomainSocketAddress that = (UnixDomainSocketAddress)o;
         return this.path.equals(that.path);
     }
 
diff --git a/src/java.base/share/classes/java/nio/StringCharBuffer.java b/src/java.base/share/classes/java/nio/StringCharBuffer.java
index 59035397c28db..40d807a653246 100644
--- a/src/java.base/share/classes/java/nio/StringCharBuffer.java
+++ b/src/java.base/share/classes/java/nio/StringCharBuffer.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -152,9 +152,8 @@ boolean isAddressable() {
     public boolean equals(Object ob) {
         if (this == ob)
             return true;
-        if (!(ob instanceof CharBuffer))
+        if (!(ob instanceof CharBuffer that))
             return false;
-        CharBuffer that = (CharBuffer)ob;
         int thisPos = this.position();
         int thisRem = this.limit() - thisPos;
         int thatPos = that.position();
diff --git a/src/java.base/share/classes/java/nio/channels/Channels.java b/src/java.base/share/classes/java/nio/channels/Channels.java
index dba3534053c03..82c12cc7eb2d0 100644
--- a/src/java.base/share/classes/java/nio/channels/Channels.java
+++ b/src/java.base/share/classes/java/nio/channels/Channels.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -86,8 +86,7 @@ private static void writeFullyImpl(WritableByteChannel ch, ByteBuffer bb)
     private static void writeFully(WritableByteChannel ch, ByteBuffer bb)
         throws IOException
     {
-        if (ch instanceof SelectableChannel) {
-            SelectableChannel sc = (SelectableChannel) ch;
+        if (ch instanceof SelectableChannel sc) {
             synchronized (sc.blockingLock()) {
                 if (!sc.isBlocking())
                     throw new IllegalBlockingModeException();