Android 和 Guice - 如何传递参数?
我希望能够注入一个对象,并将参数传递给其初始化方法。 这可能吗?
public class MyObject
{
@Inject
public MyObject(int anInteger)
{
//do something
}
}
public class MyActivity extends RoboActivity
{
@Inject (anInteger = 5) MyObject myObject;
// I want to be able to pass an object to be used when calling the
// initializer method
}
I want to be able to inject an object, and pass a parameter to its initializer method.
Is this possible?
public class MyObject
{
@Inject
public MyObject(int anInteger)
{
//do something
}
}
public class MyActivity extends RoboActivity
{
@Inject (anInteger = 5) MyObject myObject;
// I want to be able to pass an object to be used when calling the
// initializer method
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该能够使用
bindConstant()
来完成此操作并相应地对其进行注释。例如,请参阅如何注入配置参数?You should be able to do it with
bindConstant()
and annotating it accordingly. See, for example, How do I inject configuration parameters?