【发布时间】:2019-05-14 14:33:52
【问题描述】:
偶然发现了我不明白的不兼容类型错误原因。
错误:不兼容的类型:Flowable 无法转换为 Flowable 其中 T 是一个类型变量: T 扩展方法 getPackets(Class) 中声明的 Packet
为什么这段代码错了?
public Flowable<Packet> getPackets() {
.....
}
public <T extends Packet> Flowable<T> getPackets(Class<T> type) {
return getPackets().filter(type::isInstance);
}
Flowable 和 filter() 是 rxjava 的一部分,filter() 看起来像这样:
public final Flowable<T> filter(Predicate<? super T> predicate)
【问题讨论】:
-
错误发生在哪一行?你能提供一个minimal reproducible example吗?
标签: java generics lambda rx-java