内容简介:http://stackoverflow.com/questions/36521302/dagger-2-2-component-builder-module-method-deprecated
我开始使用匕首2.2,并且不建议使用“组件”构建器中的模块方法.
这是我的应用程序组件:
@Component(modules = ApplicationModule.class)
public interface ApplicationComponent {
void inject(Application application);
}
和应用模块:
@Module
public class ApplicationModule {
Application application;
public ApplicationModule(Application application) {
this.application = application;
}
@Provides
@Singleton
Application providesApplication() {
return application;
}
}
这是生成的类:
@Generated(
value = "dagger.internal.codegen.ComponentProcessor",
comments = "https://google.github.io/dagger"
)
public final class DaggerApplicationComponent implements ApplicationComponent {
private DaggerApplicationComponent(Builder builder) {
assert builder != null;
}
public static Builder builder() {
return new Builder();
}
public static ApplicationComponent create() {
return builder().build();
}
@Override
public void inject(Application application) {
MembersInjectors.<Application>noOp().injectMembers(application);
}
public static final class Builder {
private Builder() {}
public ApplicationComponent build() {
return new DaggerApplicationComponent(this);
}
/**
* @deprecated This module is declared, but an instance is not used in the component. This method is a no-op. For more, see https://google.github.io/dagger/unused-modules.
*/
@Deprecated
public Builder applicationModule(ApplicationModule applicationModule) {
Preconditions.checkNotNull(applicationModule);
return this;
}
}
}
如果不使用ComponentBuilder,如何初始化组件?
您应该阅读关于为什么不被弃用的说明.如果您正在使用像IntelliJ或Android Studio这样的IDE,您只需选择该方法并在Windows上点击Control Q即可阅读Javadoc,包括弃用通知.
Javadoc读取:
@deprecated This module is declared, but an instance is not used in the component. This method is a no-op. For more, see 07000.
从这个链接可以看到:
When the Dagger processor generates components, it only requires instances of modules and component dependencies that are explicitly needed to supply requests for a binding.
- If all of a module’s methods that are used in the component are static, Dagger does not need an instance of that module at all. Dagger can invoke the static methods directly without a module.
- If a module provides no bindings for a Component, no instance of that module is necessary to construct the graph.
可以肯定地说,您可以忽略弃用.它旨在通知您未使用的方法和模块.一旦您在子图中实际需要/使用应用程序,就需要使用模块,弃用警告将会消失.
http://stackoverflow.com/questions/36521302/dagger-2-2-component-builder-module-method-deprecated
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- Angular 开发学习 04 – 组件和模块
- Gradle自动实现Android组件化模块构建
- vue.js+webpack模块管理及组件开发(二)
- vue.js+webpack模块管理及组件开发(一)
- 从0到1实现一个模块间通信的服务组件
- 聊聊MVC和模块化以及MVVM和组件化
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
热搜:搜索排名营销大揭秘
【美】肖恩·布拉德利 / 中国人民大学出版社有限公司 / 2018-7-30 / CNY 55.00
首部大数据在我国政府管理场景中的应用实践案例读本,全面展示我国电子政务与数字化建设的成果,深度理解实施国家大数据战略的重要意义。 本书作者作为国内最早从事大数据应用研究的实践者之一,亲历了中国大数据的发展历程、主要事件、应用案例以及行业变化。 在本书中,作者将其所亲历的大数据发展历程进行了阐述,从大数据的基本概念、特点到实践解读,通俗易懂,给我们的实际工作提供了重要参考。作者将帮助读者......一起来看看 《热搜:搜索排名营销大揭秘》 这本书的介绍吧!
HEX CMYK 转换工具
HEX CMYK 互转工具
HSV CMYK 转换工具
HSV CMYK互换工具