在 Kotlin 中映射 UsbConfiguration 对象的最佳方法是如何?
你好,实际上我正在开发一个使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论