tipsy
05/06/2018, 4:56 PMfromJson(JsonToObjectMapper jsonToObjectMapper)
(java), which configures how my library does json-mapping:
public interface JsonToObjectMapper {
<T> T map(String json, Class<T> targetClass);
}
calling this method works fine from java, but kotlin is unable to infer types. if i try to to:
val gson = GsonBuilder().create()
myPlugin.fromJson(gson::fromJson)
i just get None of the following functions can be called with the arguments supplied.
any ideas?Andreas Sinz
05/06/2018, 5:24 PMJsonToObjectMapper
is a kotlin interface, right?tipsy
05/06/2018, 5:25 PMAndreas Sinz
05/06/2018, 5:27 PMmyPlugin.fromJson { json, cls -> gson.fromJson(json, cls) }
Andreas Sinz
05/06/2018, 5:28 PMgson::fromJson
Andreas Sinz
05/06/2018, 5:29 PMtipsy
05/06/2018, 5:31 PMtipsy
05/06/2018, 5:31 PMAndreas Sinz
05/06/2018, 5:33 PMJsonToObjectMapper
only have a single method?tipsy
05/06/2018, 5:33 PMAndreas Sinz
05/06/2018, 5:35 PMtypealias JsonToObjectMapper<T> = (String, Class<T>) -> T
fun MyPlugin.fromJson(map: JsonToObjectMapper<T>) {
....
}
Andreas Sinz
05/06/2018, 5:36 PMmyPlugin.fromJson(gson::fromJson)
workstipsy
05/06/2018, 5:37 PMAndreas Sinz
05/06/2018, 5:42 PMkotlin-stdlib
is included in the java project), function types are just functional interfacestipsy
05/06/2018, 5:44 PMtipsy
05/06/2018, 5:51 PMType inference failed: Not enough information to infer parameter T in
fun <T> fromJson(map: JsonToObjectMapper<T> /* = (String, Class<T>) → T */): Unit
tipsy
05/06/2018, 5:51 PM