返回自定义对象列表时,RxJava 会突出显示错误但会编译 [英] When returning a List of custom Objects RxJava highlights an error but compiles

查看:37
本文介绍了返回自定义对象列表时,RxJava 会突出显示错误但会编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在进行 RxJava 调用,我订阅的最终结果是预订列表.

I'm making an RxJava call and the end result I subscribe to is a List of Booking.

代码工作正常,但我得到了这个烦人的亮点:

The code works fine but I get this annoying highlight:

演员表在这里不起作用,因为我无法将 List 转换为 List .

A cast doesn't work here because I can't cast List <Booking> to List <Object>.

好吧,你可能会说我应该用 lambda 表达式替换它,但是在 call() 方法中,我需要调用一个接受 List 的方法代码>作为参数:

Ok, you might say I should just replace it with a lambda expression, but in the call() method I need to call a method that takes List <Booking> as a parameter:

如何避免在任何这些情况下突出显示?

How can I avoid highlighting in any of these cases?

推荐答案

您可以向泛型方法添加显式类型,例如 flatMap.有时 Java 8 类型推断效果不佳.

You can add an explicit type to the generic methods, such as <Booking>flatMap. Sometimes Java 8 type inference doesn't work well.

这篇关于返回自定义对象列表时,RxJava 会突出显示错误但会编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆