[Solved] Having trouble implementing a nested class comparator


You should provide inner class instance into Arrays.sort to compare points from view of parent class instance. To do it you should not create new instance in main() function, but get it from Point instance.

So, in main function you should use something like this:

Point pivot;
... // set up pivot point here
Arrays.sort(myPoints, pivot.slopeOrder());

Also you should remove “static” from nested class definition so it becomes inner class, that can actually access its parent members:

private class bySlope implements Comparator<Point> {

2

solved Having trouble implementing a nested class comparator