I'm learning Dagger2 via their tutorial but am blocked at part 5. I've implemented everything in Kotlin (jvm) and the logic/behavior matches the tutorial in working order to this point.
However, I'm unable to create SystemOutModule
and unsure whether I'm mistaken somewhere with Dagger, or in my translation of their module class.
/**
* Tutorial's Java.
*/
@Module
abstract class SystemOutModule {
@Provides
static Outputter textOutputter() {
return System.out::println;
}
}
/**
* My Kotlin.
*/
@Module
object SystemOutModule {
@JvmSuppressWildcards
@Provides
fun textOutputter(): (String) -> Unit = { println(it) }
}
The build fails with this error:
~~ ./gradlew clean build
> Task :app:kaptKotlin FAILED
e: /Users/eric/IdeaProjects/atm/app/build/tmp/kapt3/stubs/main/com/es0329/atm/CommandRouterFactory.java:7: error: [Dagger/MissingBinding] com.es0329.atm.Outputter cannot be provided without an @Provides-annotated method.
public abstract interface CommandRouterFactory {
^
com.es0329.atm.Outputter is injected at
com.es0329.atm.HelloWorldCommand(outputter)
com.es0329.atm.HelloWorldCommand is injected at
com.es0329.atm.HelloWorldModule.helloWorldCommand(command)
com.es0329.atm.Command is injected at
com.es0329.atm.CommandRouter(command)
com.es0329.atm.CommandRouter is provided at
com.es0329.atm.CommandRouterFactory.router()
FAILURE: Build failed with an exception.