Refactor method name dispatching to switch statements in AutowireUtils
Closes gh-25199
This commit is contained in:
parent
b9e52a8089
commit
eb3be3ad88
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -272,23 +272,21 @@ abstract class AutowireUtils {
|
||||||
|
|
||||||
private final ObjectFactory<?> objectFactory;
|
private final ObjectFactory<?> objectFactory;
|
||||||
|
|
||||||
public ObjectFactoryDelegatingInvocationHandler(ObjectFactory<?> objectFactory) {
|
ObjectFactoryDelegatingInvocationHandler(ObjectFactory<?> objectFactory) {
|
||||||
this.objectFactory = objectFactory;
|
this.objectFactory = objectFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||||
String methodName = method.getName();
|
switch (method.getName()) {
|
||||||
if (methodName.equals("equals")) {
|
case "equals":
|
||||||
// Only consider equal when proxies are identical.
|
// Only consider equal when proxies are identical.
|
||||||
return (proxy == args[0]);
|
return (proxy == args[0]);
|
||||||
}
|
case "hashCode":
|
||||||
else if (methodName.equals("hashCode")) {
|
// Use hashCode of proxy.
|
||||||
// Use hashCode of proxy.
|
return System.identityHashCode(proxy);
|
||||||
return System.identityHashCode(proxy);
|
case "toString":
|
||||||
}
|
return this.objectFactory.toString();
|
||||||
else if (methodName.equals("toString")) {
|
|
||||||
return this.objectFactory.toString();
|
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return method.invoke(this.objectFactory.getObject(), args);
|
return method.invoke(this.objectFactory.getObject(), args);
|
||||||
|
|
Loading…
Reference in New Issue