开发者社区> 问答> 正文

找不到symbol的错误?

使用this不是引用创建的对象么?

public class Point implements Comparable<Point> {
    int x, y;
    public final Comparator<Point> SLOPE_ORDER = new ByOrder();

    private class ByOrder implements Comparator<Point> {
        public int compare(Point one, Point two) {
            return this.slopeTo(one) < this.slopeTo(two) ? -1: 
                   this.slopeTo(one) > this.slopeTo(two) ? 1:0;
        }
    }

    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public void draw() {
        StdDraw.circle(x, y, 00);
    }

    public void drawTo(Point that) {
        StdDraw.line(this.x, this.y, that.x, that.y);
    }

    public String toString() {
        String point_string = '(' + String.valueOf(x) + ',' + 
                                    String.valueOf(y) + ')';
        return point_string;
    }

    public int compareTo(Point that) {
        return ((this.y < that.y) || (this.y == that.y && this.x < that.x)) ? -1:
                (this.y > that.y) ? 1:0;

    }
    public double slopeTo(Point that) {
        double slope = (that.y - this.y) / (that.x - this.x);
        return slope;
    }

}

Point.java:10: error: cannot find symbol return this.slopeTo(one) <
this.slopeTo(two) ? -1:

symbol: method slopeTo(Point)

展开
收起
蛮大人123 2016-02-25 14:11:23 2280 0
1 条回答
写回答
取消 提交回答
  • 我说我不帅他们就打我,还说我虚伪

    你的 this 是 ByOrder 对象,而 ByOrder 不在 Point 的继承树上。

    2019-07-17 18:47:28
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载