Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ public static Type resolveType(Type genericType, @Nullable Class<?> contextClass
resolvedTypeVariable = ResolvableType.forVariableBounds(typeVariable);
}
if (resolvedTypeVariable != ResolvableType.NONE) {
Type type = resolvedTypeVariable.getType();
if (type instanceof ParameterizedType) {
return resolveType(type, contextClass);
}
Class<?> resolved = resolvedTypeVariable.resolve();
if (resolved != null) {
return resolved;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Supplier;

import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -250,6 +251,15 @@ void resolveTypeFromGenericDefaultMethod() {
assertThat(resolvedType).isEqualTo(InheritsDefaultMethod.ConcreteType.class);
}

@Test
void resolveTypeFromNestedParameterizedType() {
Type resolvedType = resolveType(method(MyInterfaceType.class, "get").getGenericReturnType(), MyCollectionInterfaceType.class);
assertThat(resolvedType).isEqualTo(method(MyCollectionInterfaceType.class, "get").getGenericReturnType());

resolvedType = resolveType(method(MyInterfaceType.class, "get").getGenericReturnType(), MyOptionalInterfaceType.class);
assertThat(resolvedType).isEqualTo(method(MyOptionalInterfaceType.class, "get").getGenericReturnType());
}

private static Method method(Class<?> target, String methodName, Class<?>... parameterTypes) {
Method method = findMethod(target, methodName, parameterTypes);
assertThat(method).describedAs(target.getName() + "#" + methodName).isNotNull();
Expand All @@ -258,12 +268,29 @@ private static Method method(Class<?> target, String methodName, Class<?>... par


public interface MyInterfaceType<T> {
default T get() {
return null;
}
}

public class MySimpleInterfaceType implements MyInterfaceType<String> {
}

public class MyParameterizedInterfaceType<P> implements MyInterfaceType<Collection<P>> {
}

public class MyOptionalInterfaceType extends MyParameterizedInterfaceType<Optional<String>> {
@Override
public Collection<Optional<String>> get() {
return super.get();
}
}

public class MyCollectionInterfaceType implements MyInterfaceType<Collection<String>> {
@Override
public Collection<String> get() {
return MyInterfaceType.super.get();
}
}

public abstract class MyAbstractType<T> implements MyInterfaceType<T> {
Expand Down