Use instanceof pattern in BindingReflections 52/101352/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 30 May 2022 08:40:47 +0000 (10:40 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 30 May 2022 08:40:47 +0000 (10:40 +0200)
Reduce the number of casts.

Change-Id: I220b063f9ce81d7487fdf35ef2648193cb7c4cb6
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-spec-util/src/main/java/org/opendaylight/mdsal/binding/spec/reflect/BindingReflections.java

index 0f1dc3e9b90fc2b18ee2ec508e928fc9d4a6c2bc..92d4d784ebd140cb24c7e9509210910b4a004a8a 100644 (file)
@@ -170,8 +170,8 @@ public final class BindingReflections {
         Type futureType = targetMethod.getGenericReturnType();
         Type rpcResultType = ClassLoaderUtils.getFirstGenericParameter(futureType).orElse(null);
         Type rpcResultArgument = ClassLoaderUtils.getFirstGenericParameter(rpcResultType).orElse(null);
-        if (rpcResultArgument instanceof Class && !Void.class.equals(rpcResultArgument)) {
-            return Optional.of((Class) rpcResultArgument);
+        if (rpcResultArgument instanceof Class cls && !Void.class.equals(rpcResultArgument)) {
+            return Optional.of(cls);
         }
         return Optional.empty();
     }
@@ -510,8 +510,8 @@ public final class BindingReflections {
     }
 
     private static Optional<Type> genericParameter(final Type type, final int offset) {
-        if (type instanceof ParameterizedType) {
-            final Type[] parameters = ((ParameterizedType) type).getActualTypeArguments();
+        if (type instanceof ParameterizedType parameterized) {
+            final Type[] parameters = parameterized.getActualTypeArguments();
             if (parameters.length > offset) {
                 return Optional.of(parameters[offset]);
             }
@@ -543,8 +543,8 @@ public final class BindingReflections {
                 }
 
                 final Object obj = field.get(null);
-                if (obj instanceof QName) {
-                    return Optional.of((QName) obj);
+                if (obj instanceof QName qname) {
+                    return Optional.of(qname);
                 }
             } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) {
                 /*