Skip to content

Commit 544e9bb

Browse files
committed
Merge pull request #24525 from chenqimiao
* pr/24525: Polish "Reuse ResolvableType in getDependencyType" Reuse ResolvableType in getDependencyType Closes gh-24525
2 parents f64ede3 + f1fe16e commit 544e9bb

File tree

1 file changed

+2
-19
lines changed

1 file changed

+2
-19
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/config/DependencyDescriptor.java

+2-19
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import java.io.Serializable;
2222
import java.lang.annotation.Annotation;
2323
import java.lang.reflect.Field;
24-
import java.lang.reflect.ParameterizedType;
25-
import java.lang.reflect.Type;
2624
import java.util.Map;
2725
import java.util.Optional;
2826

@@ -365,23 +363,8 @@ public String getDependencyName() {
365363
public Class<?> getDependencyType() {
366364
if (this.field != null) {
367365
if (this.nestingLevel > 1) {
368-
Type type = this.field.getGenericType();
369-
for (int i = 2; i <= this.nestingLevel; i++) {
370-
if (type instanceof ParameterizedType) {
371-
Type[] args = ((ParameterizedType) type).getActualTypeArguments();
372-
type = args[args.length - 1];
373-
}
374-
}
375-
if (type instanceof Class) {
376-
return (Class<?>) type;
377-
}
378-
else if (type instanceof ParameterizedType) {
379-
Type arg = ((ParameterizedType) type).getRawType();
380-
if (arg instanceof Class) {
381-
return (Class<?>) arg;
382-
}
383-
}
384-
return Object.class;
366+
Class<?> clazz = getResolvableType().getRawClass();
367+
return (clazz != null ? clazz : Object.class);
385368
}
386369
else {
387370
return this.field.getType();

0 commit comments

Comments
 (0)