Subcomponents require public constructors on pure-static modules
See original GitHub issueExample:
@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:
- Created 7 years ago
- Reactions:2
- Comments:16
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Also happens for abstract modules of subcomponents which only have
@Binds
methods.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.