I use an in-house Java framework containing the following classes (simplified for demonstration):
public interface SomeAction<T, R> {
R run(T t);
}
public class ConcreteAction implements SomeAction<Integer, String> {
@Override
public String run(Integer arg) {
return "abc";
}
}
public class ActionFactory {
public <A extends SomeAction<T, R>, T, R> SomeAction<T, R> create(Class<A> clz) throws IllegalAccessException, InstantiationException {
return clz.newInstance();
}
}
Calling the factory method from Kotlin in a java-way works ok:
ActionFactory().create(ConcreteAction::class.java).run(1)
Then I created the following extension method to make it more concise:
inline fun <reified A : SomeAction<T, R>, T, R> ActionFactory.create(): SomeAction<T, R> {
return create(A::class.java)
}
But a call to ActionFactory().create<ConcreteAction>().run(1) fails with the error 3 type arguments for inline fun ...
Are there any ways to make it work without touching the java code?