|
23 | 23 | import java.util.Arrays;
|
24 | 24 | import java.util.Collections;
|
25 | 25 | import java.util.List;
|
26 |
| -import java.util.Optional; |
27 | 26 | import java.util.function.Predicate;
|
28 | 27 | import java.util.stream.Collectors;
|
29 | 28 | import java.util.stream.Stream;
|
30 | 29 |
|
| 30 | +import org.jetbrains.annotations.NotNull; |
| 31 | + |
31 | 32 | import org.springframework.core.KotlinDetector;
|
32 | 33 | import org.springframework.core.MethodParameter;
|
33 | 34 | import org.springframework.core.ResolvableType;
|
@@ -282,17 +283,22 @@ public static void setField(Field field, Object target, @Nullable Object value)
|
282 | 283 | * @param type must not be {@literal null}.
|
283 | 284 | * @param constructorArguments must not be {@literal null}.
|
284 | 285 | * @return a {@link Constructor} that is compatible with the given arguments.
|
285 |
| - * @deprecated since 3.5, return type will change to nullable instead of Optional. |
286 | 286 | */
|
287 |
| - @Deprecated |
288 |
| - public static Optional<Constructor<?>> findConstructor(Class<?> type, Object... constructorArguments) { |
| 287 | + @Nullable |
| 288 | + @SuppressWarnings("unchecked") |
| 289 | + public static <T> Constructor<T> findConstructor(Class<T> type, Object... constructorArguments) { |
289 | 290 |
|
290 | 291 | Assert.notNull(type, "Target type must not be null");
|
291 | 292 | Assert.notNull(constructorArguments, "Constructor arguments must not be null");
|
292 | 293 |
|
293 |
| - return Arrays.stream(type.getDeclaredConstructors())// |
294 |
| - .filter(constructor -> argumentsMatch(constructor.getParameterTypes(), constructorArguments))// |
295 |
| - .findFirst(); |
| 294 | + for (@NotNull |
| 295 | + Constructor<?> declaredConstructor : type.getDeclaredConstructors()) { |
| 296 | + if (argumentsMatch(declaredConstructor.getParameterTypes(), constructorArguments)) { |
| 297 | + return (Constructor<T>) declaredConstructor; |
| 298 | + } |
| 299 | + } |
| 300 | + |
| 301 | + return null; |
296 | 302 | }
|
297 | 303 |
|
298 | 304 | /**
|
|
0 commit comments