@@ -29,6 +29,13 @@ static <T> T instantiate(Class<T> spiInterface, Class<? extends T> implementatio
29
29
.invoke (findConstructor (spiInterface , implementationClass ));
30
30
}
31
31
32
+ @ SuppressWarnings ("unchecked" )
33
+ private static <T > Constructor <? extends T > findConstructor (Class <T > spiInterface ,
34
+ Class <? extends T > implementationClass ) {
35
+
36
+ return (Constructor <? extends T >) findBestConstructor (spiInterface , implementationClass );
37
+ }
38
+
32
39
/**
33
40
* Find the "best" constructor for the supplied implementation class.
34
41
*
@@ -38,9 +45,8 @@ static <T> T instantiate(Class<T> spiInterface, Class<? extends T> implementatio
38
45
* Otherwise, this method throws an exception stating that it failed to
39
46
* find a suitable constructor.
40
47
*/
41
- @ SuppressWarnings ("unchecked" )
42
- private static <T , V extends T > Constructor <? extends V > findConstructor (Class <T > spiInterface ,
43
- Class <V > implementationClass ) {
48
+ private static <T > Constructor <?> findBestConstructor (Class <T > spiInterface ,
49
+ Class <? extends T > implementationClass ) {
44
50
45
51
Preconditions .condition (!ReflectionUtils .isInnerClass (implementationClass ),
46
52
() -> String .format ("The %s [%s] must be either a top-level class or a static nested class" ,
@@ -50,12 +56,12 @@ private static <T, V extends T> Constructor<? extends V> findConstructor(Class<T
50
56
51
57
// Single constructor?
52
58
if (constructors .length == 1 ) {
53
- return ( Constructor < V >) constructors [0 ];
59
+ return constructors [0 ];
54
60
}
55
61
// Find default constructor.
56
62
for (Constructor <?> constructor : constructors ) {
57
63
if (constructor .getParameterCount () == 0 ) {
58
- return ( Constructor < V >) constructor ;
64
+ return constructor ;
59
65
}
60
66
}
61
67
// Otherwise...
0 commit comments