I've attempted to sort a Java ArrayList by using Collections, but it's not working, even though I tried to follow code from other questions.
I have a class called PcdPoint that has the methods getScore() and getType(), where getScore() returns a double and getType() returns an integer. (not Atomic)
The following code should work but it's giving me an error: "Cannot infer type <any>"
Collections.sort(pointList,
Comparator.comparing((PcdPoint a, PcdPoint b) -> a.getScore() - b.getScore())
.thenComparing((PcdPoint a, PcdPoint b) -> a.getType() - b.getType()));
So I tried looking up the documentation and tried to do this instead
Collections.sort(pointList,
Comparator<PcdPoint>.comparing((a, b) -> a.getScore() - b.getScore())
.thenComparing((a, b) -> a.getType() - b.getType()));
and
Collections.sort(pointList,
Comparator.comparing((a, b) -> a.getScore() - b.getScore())
.thenComparing((a, b) -> a.getType() - b.getType()));
But neither of those seem to work.