内容简介: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和组件化
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Ajax与PHP Web开发
达里 / 王德民、王新颖、刘昕 / 人民邮电出版社 / 2007-4 / 39.00元
本书指导读者使用Ajax、PHP及其他相关技术建立快速响应的网页。本书不仅从Ajax的客户端和服务器端技术两个方面指导读者逐步掌握Ajax基础应用,还通过实例详细演示了Ajax表单验证、Ajax聊天室、Ajax Suggest、使用SVG实现的Ajax实时绘图程序、Ajax Grid、Ajax RSS阅读器和Ajax拖放等的实现过程。同时还介绍了在Windows和UNIX系统下的应用程序环境配置和......一起来看看 《Ajax与PHP Web开发》 这本书的介绍吧!