Affects PMD Version:
6.1.0
Rule:
category/java/codestyle.xml/UnnecessaryConstructor
Description:
Using Dagger dependency injection, I am required to have an empty constructor in my class which extends an abstract base class. The instance is provided using Dagger multibinding.
Code Sample demonstrating the issue:
// MainViewModel.java
public class MainViewModel extends BaseViewModel {
@Inject
public MainViewModel() {
super();
}
// ...
}
// ViewModelModule.java
@Module
abstract class ViewModelModule {
@Binds
@IntoMap
@ViewModelKey(MainViewModel.class)
abstract ViewModel bindMainViewModel(MainViewModel viewModel);
// ...
}
The error message (when removing the empty constructor to fix the PMD warning) is:
[dagger.android.AndroidInjector.inject(T)] MainViewModel cannot be provided without an @Inject constructor or from an @Provides-annotated method. This type supports members injection but cannot be implicitly provided.
Running PMD through: Gradle
It would be great to be able to skip annotated (e.g. @Inject
) constructors, as this rule is still useful for "normal" constructors.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4