在 Kotlin 中映射 UsbConfiguration 对象的最佳方法是如何?

发布于 2025-01-10 13:45:59 字数 917 浏览 4 评论 0原文

你好,实际上我正在开发一个使用USB的应用程序,我需要从这个映射结构返回UsbConfiguration,但编译器错误是:

Type checking has run into a recursive problem. Easiest workaround: specify types of your declarations explicitly

这是来自方法的调用:

   @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
private fun getConfiguration(index:Int?):
        Map<String, Any> {
    val device = usbDevice
    val configuration: UsbConfiguration = device!!.getConfiguration(index!!)
    val map = configuration.toMap() + ("index" to index)
    return map
}

这是getInterface(it)中特定问题的部分).toMap():

fun UsbConfiguration.toMap() = mapOf(
    "id" to id,
    "interfaces" to List(interfaceCount) {
        getInterface(it).toMap() }
)

从库到方法 getInterface(int index) 的代码

 @NonNull
public UsbInterface getInterface(int index) {
    throw new RuntimeException("Stub!");
}

Hello actually I'm developing an app with the use of USB, I need return the UsbConfiguration from this map structure but the compiler error is:

Type checking has run into a recursive problem. Easiest workaround: specify types of your declarations explicitly

This is the call from the method:

   @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
private fun getConfiguration(index:Int?):
        Map<String, Any> {
    val device = usbDevice
    val configuration: UsbConfiguration = device!!.getConfiguration(index!!)
    val map = configuration.toMap() + ("index" to index)
    return map
}

And this is the part with the problem specific in getInterface(it).toMap():

fun UsbConfiguration.toMap() = mapOf(
    "id" to id,
    "interfaces" to List(interfaceCount) {
        getInterface(it).toMap() }
)

The code from library to the method getInterface(int index)

 @NonNull
public UsbInterface getInterface(int index) {
    throw new RuntimeException("Stub!");
}

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文