Skip to content

Commit 36cf1ac

Browse files
committed
Apply "instanceof pattern matching" in AopProxyUtils
1 parent d533eb4 commit 36cf1ac

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

spring-aop/src/main/java/org/springframework/aop/framework/AopProxyUtils.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636

3737
/**
3838
* Utility methods for AOP proxy factories.
39-
* Mainly for internal use within the AOP framework.
39+
*
40+
* <p>Mainly for internal use within the AOP framework.
4041
*
4142
* <p>See {@link org.springframework.aop.support.AopUtils} for a collection of
4243
* generic AOP utility methods which do not depend on AOP framework internals.
@@ -59,10 +60,10 @@ public abstract class AopProxyUtils {
5960
*/
6061
@Nullable
6162
public static Object getSingletonTarget(Object candidate) {
62-
if (candidate instanceof Advised) {
63-
TargetSource targetSource = ((Advised) candidate).getTargetSource();
64-
if (targetSource instanceof SingletonTargetSource) {
65-
return ((SingletonTargetSource) targetSource).getTarget();
63+
if (candidate instanceof Advised advised) {
64+
TargetSource targetSource = advised.getTargetSource();
65+
if (targetSource instanceof SingletonTargetSource singleTargetSource) {
66+
return singleTargetSource.getTarget();
6667
}
6768
}
6869
return null;
@@ -82,8 +83,8 @@ public static Class<?> ultimateTargetClass(Object candidate) {
8283
Assert.notNull(candidate, "Candidate object must not be null");
8384
Object current = candidate;
8485
Class<?> result = null;
85-
while (current instanceof TargetClassAware) {
86-
result = ((TargetClassAware) current).getTargetClass();
86+
while (current instanceof TargetClassAware targetClassAware) {
87+
result = targetClassAware.getTargetClass();
8788
current = getSingletonTarget(current);
8889
}
8990
if (result == null) {

0 commit comments

Comments
 (0)