匕首握把多键不能支持列表< t>类型?

发布于 2025-02-09 09:25:51 字数 231 浏览 1 评论 0 原文

我在使用它的刀柄上有一个问题,提供了列表示例,如下:

[Dagger/MissingBinding] java.util.List<? extends okhttp3.Interceptor> cannot be provided without an @Provides-annotated method.

那么,我该怎么办?我将其更改为设置,但是我想要一个排序的数组。

I have a problem with Hilt by using it provides List example, the erroe message as below:

[Dagger/MissingBinding] java.util.List<? extends okhttp3.Interceptor> cannot be provided without an @Provides-annotated method.

so,what can i do for this?shoud i change it to Set,but i want a sorted array..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瀟灑尐姊 2025-02-16 09:25:51

多接口不支持列表,只有集合和地图。在匕首中,模块不被假定为特定顺序,尤其是因为它们在组件中被删除。

假设您希望Module1提供Interceptor1和Module2提供interceptor2,并且您希望它们按顺序安装。即使匕首是要保证字母排序和深度 - first遍历,如果模块包括 module1和module2,然后添加取决于模块2的模块,然后无论模块的订购模块如何在module1之前安装。

如果您想要一个订购的列表,则需要立即将其安装为整个列表,否则您需要自己对内容进行分类。为此,一种技术是使用MAP多键,您可以在其中安装一个可排序的键(“ 001初始拦截器”,“ 101第二层”,“ 201第三层”)安装性和订单而不依赖于模块加载顺序。

Multibindings do not support Lists, only Sets and Maps. In Dagger modules are not assumed to be included in a particular order, especially because they are de-duplicated within a component.

Let's say you want Module1 to provide Interceptor1 and Module2 to provide Interceptor2, and you want them installed in order. Even if Dagger were to guarantee alphabetic sorting and depth-first traversal, if ModuleB includes Module1 and Module2 and then you add ModuleA that depends on Module2, then regardless of ModuleB's ordering Module2 would be installed before Module1 is.

If you want an ordered list, you'll need to install it as a whole List you provide at once, or you'll need to sort the contents yourself. One technique for this is using Map Multibindings where you install a sortable key ("001 initial interceptor", "101 second layer", "201 third layer") etc and then traverse the Map in order of sorted key: this should give you the installability and order without relying on module loading order.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文