【发布时间】:2018-01-21 20:49:19
【问题描述】:
我有一个类似这样的 Kotlin 类:
class MyClass @Inject constructor(val work: (Int) -> Unit)) { ... }
bind 和 @Provides 都不起作用:
class FunctionModule : AbstractModule() {
override fun configure() {
bind(object : TypeLiteral<Function1<Int, Unit>>() {}).toInstance({})
}
@Provides
fun workFunction(): (Int) -> Unit = { Unit }
}
}
我不断收到错误:
没有实现 kotlin.jvm.functions.Function1 已绑定。
如何使用 Guice 为 Kotlin 函数注入实现?
【问题讨论】:
-
注意
{ Unit }可以简化为{}