groupBy()破解hashCode()?

时间:2014-11-08 05:06:10

标签: java groovy rx-java

目前我的应用程序正在尝试使用RxJava groupBy()来理论上应该是一项简单的任务。问题是我试图分组的类(MyClass)的hashCode()方法被破坏了。

我为解决这个问题所做的工作如下:

myValues
    // Group by the string representation, rather than actual class
    .groupBy { it.toString() }
    .map { GroupedObservable.from(new MyClass(it.getKey()), it) }

MyClass的设置如下:

class MyClass {
    MyClass(String initialString) {
        // Some constructor here
    }
}

问题是GroupedObservable.from()是一种弃用的方法。

通常我都赞成修复hashCode()方法以支持正确的groupBy(),但这是在外部库中。我在那里尝试了子类化和覆盖hashCode()方法,但我仍然遇到问题,因为我需要映射回原始类。

是否有正确的方法可以解决RxJava中损坏的hashCode()方法?

0 个答案:

没有答案