Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AssistedInject for a type with generic parameter produces code that doesn't compile

See original GitHub issue

Dagger 2.31 The following class generates code that doesn’t compile:

package com.example

import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject

class AssistedInjectRepro<T> @AssistedInject constructor(
    @Assisted obj: T,
) {

    interface Factory {

        fun <T> create(
            obj: T,
        ): AssistedInjectRepro<T>

generated code:

// Generated by Dagger (
package com.example;

import dagger.internal.InstanceFactory;
import javax.inject.Provider;

public class AssistedInjectRepro_Factory_Impl implements AssistedInjectRepro.Factory {
  private final AssistedInjectRepro_Factory<T> delegateFactory;

  AssistedInjectRepro_Factory_Impl(AssistedInjectRepro_Factory<T> delegateFactory) {
    this.delegateFactory = delegateFactory;

  public <T> AssistedInjectRepro<T> create(T obj) {
    return delegateFactory.get(obj);

  public static <T> Provider<AssistedInjectRepro.Factory> create(
      AssistedInjectRepro_Factory<T> delegateFactory) {
    return InstanceFactory.create(new AssistedInjectRepro_Factory_Impl(delegateFactory));

which fails with

> Task :app:kaptDebugKotlin FAILED
...generated/source/kapt/debug/com/example/ error: cannot find symbol
  private final AssistedInjectRepro_Factory<T> delegateFactory;
  symbol:   class T
  location: class AssistedInjectRepro_Factory_Impl/.../build/generated/source/kapt/debug/com/example/ error: cannot find symbol
  AssistedInjectRepro_Factory_Impl(AssistedInjectRepro_Factory<T> delegateFactory) {
  symbol:   class T
  location: class AssistedInjectRepro_Factory_Impl
FAILURE: Build failed with an exception.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:12
  • Comments:12

github_iconTop GitHub Comments

bcorsocommented, Jan 16, 2021

@lwasyl, thanks for the repro case!

I agree we should support this. I should be able to get a fix out soon.

bcorsocommented, Jan 28, 2021

@lwasyl, just a heads up that we’re still considering this but it’s unlikely it’ll be in the next release.

For now, I’m going to add some validation in our processor so that at least we’ll catch this and fail fast with a better error message rather than generating invalid java.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can I use some kind of assisted Inject with Dagger?
Because AutoFactory generates code, you don't need to write an interface to represent the constructor: AutoFactory will write a brand new ...
Read more >
How To Use Generics in Go | DigitalOcean
By declaring C any inside your type parameters, your code says, “create a generic type parameter named C that I can use in...
Read more >
Assisted Injection - Dagger
Dagger is a fully static, compile-time dependency injection framework for both Java and Android. It is developed by the Java Core Libraries Team...
Read more >
How to Set up Dagger With ViewModel & Saved State Module
Neither one of these is great because they makes your code more fragile ... The generic parameter T serves as a way to...
Read more >
Connecting The Dots: Dagger • ViewModel • Saved State
I don't describe here, how to setup Dagger with ViewModel as there ... The generic parameter T serves as way to inform AssistedInject...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found