Java varargs构造函数在子类构造函数中给出错误

问题描述 投票:-1回答:1

我有两个班:FinishButtonChangeSpeedButtonFinishButton是父类,但它来自不同的包,它是另一个类的子类。它有2个构造函数:

public class FinishButton extends Button {

    public FinishButton(Point...points) {
        super(Response.SLOW,Type.HOLD,points);
    }
    public FinishButton() {
        this(new Point(width-75,height-75),
                new Point(width-75,height-15),
                new Point(width-15,height-15),
                new Point(width-15,height-75));
    }

    public void function() {
        nextPanel();
    }

    public void draw(Graphics g) {
        super.draw(g);
        this.xpoints[0] = 0;
        g.setColor(Defaults.GRAPHIC_COLOR);
        int[] xPoints = { 
                width-45-(int)((20*Math.sqrt(3))/2),
                width-45-(int)((20*Math.sqrt(3))/2),
                width-45+(int)((20*Math.sqrt(3))/2)
        },
                yPoints = {
                height-65,height-25,height-45
        };
        int nPoints = 3;
        g.fillPolygon(xPoints, yPoints, nPoints);
    }

}

这些类正在进行中,但ChangeSpeedButton看起来像这样:

public class ChangeSpeedButton extends FinishButton {

    public ChangeSpeedButton() {
        super(new Point(width/2-30,height-75),
                new Point(width/2-30,height-15),
                new Point(width/2+30,height-15),
                new Point(width/2+30,height-75));
    }

}

奇怪的是FinishButton在重载自己的构造函数时完美地处理了varargs,但由于某种原因在ChangeSpeedButton的构造函数上,Eclipse告诉我

“删除匹配'FinishButton()'或”更改构造函数'FinishButton()'的参数:添加参数'Point,Point,Point,Point'“。

有谁知道为什么它在ChangeSpeedButton上给我一个错误?

编辑:我添加了完整的课程。根据要求,这里是Point类:

public class Point {

    private double x,y;

    public double getX() { return x; }
    public double getY() { return y; }

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

    public String toString() {
        return "Point: ("+x+", "+y+")";
    }

}

也许这与Button类是嵌套类这一事实有关?

java constructor subclass variadic-functions superclass
1个回答
0
投票

哦,我的天啊。我太笨了我打开了2个FinishButton文件,即使我保存了其中一个正确的更改,ChangeSpeedButton只查看过时的文件。

© www.soinside.com 2019 - 2024. All rights reserved.