question-mark
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.

Subcomponents require public constructors on pure-static modules

See original GitHub issue

Example:

@Module
class MyModule {
    @Provides
    static String provideStaticDependency() {
        return "a static dependency";
    }

    private MyModule() {
        throw new UnsupportedOperationException("No instances!");
    }
}

@Subcomponent(modules = MyModule.class)
interface MySubComponent {
    String staticDependency();
}

@Component
interface MyComponent {
    MySubComponent subComponent();
}

Dagger complains:

error: MySubComponent requires modules which have no visible default constructors. Add the following modules as parameters to this method: MyModule
    MySubComponent subComponent();
                   ^

If I make the module constructor public, it solves the warning, but the generated code never calls that constructor (as is evidenced by the fact that my application never crashes).

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:16

github_iconTop GitHub Comments

2reactions
gabrielittnercommented, May 6, 2016

Also happens for abstract modules of subcomponents which only have @Binds methods.

1reaction
gk5885commented, Dec 26, 2016

Hey, thanks for the bump. I was actually working on this just the other day because it was annoying me too and we should have fix for the next release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Subcomponent.Builder is missing setters - Stack Overflow
You require your Module: @PerFragment @Subcomponent(modules = {DIMarcaModulo.class}) public interface DIMarcaComponent extends ...
Read more >
Private Constructors - C# Programming Guide - Microsoft Learn
Private constructors are used to prevent creating instances of a class when there are no instance fields or methods, such as the Math...
Read more >
constructor - JavaScript - MDN Web Docs - Mozilla
The constructor method is a special method of a class for creating and initializing an object instance of that class.
Read more >
Constructors in Python - GeeksforGeeks
In Python the __init__() method is called the constructor and is always called when an object is created. Syntax of constructor declaration :...
Read more >
Constructors and Destructors - Manual - PHP
If a class has no constructor, or the constructor has no required arguments, ... public function __construct(protected int $x, protected int $y =...
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found