Hilt Basics Interview Questions

ARCHITECTURE › Dependency Injection

Walk me through what you'd do when Hilt gives you a compile-time error saying it can't find a binding for a type. What's your debugging process?

What a strong answer covers: You check whether the type has an @Inject constructor or a matching @Provides/@Binds method in a module, confirm that module's @InstallIn component actually matches or is an ancestor of where the type is being injected, and check for a missing @Qualifier if multiple bindings of the same type exist in scope. The trap is assuming Hilt 'should just know' how to build something, when it is strictly a compile-time graph that requires every binding to be explicitly declared and correctly scoped.

You have a class that needs both Hilt-provided dependencies and a value only known at runtime, like a userId passed into a screen. How do you handle that with Hilt?

What a strong answer covers: You use assisted injection with @AssistedInject on the constructor and an @AssistedFactory interface, so Dagger supplies every graph dependency automatically and the generated factory only takes the runtime parameter, rather than manually constructing the class or building a bespoke ViewModelProvider.Factory. The trap is trying to smuggle the runtime value into the graph as if it were a dependency, or reaching for a full custom factory when assisted injection is the purpose-built, simpler tool.

When would you deliberately avoid Hilt for a module in your app, even though the rest of the app uses it?

What a strong answer covers: Avoid Hilt in a shared Kotlin Multiplatform module or a plain Kotlin library with no Android dependency, since Hilt is Android-only and pulls in Android Gradle Plugin tooling that such a module shouldn't depend on; use manual constructor injection or a lighter runtime DI there instead. Also consider skipping it for a small feature module meant to be published and reused outside this app, where forcing every consumer into your Hilt component graph is too heavy a constraint; the trap is wiring every module through Hilt reflexively even when it fights the module's actual constraints.

Back to Hilt Basics