Java ArrayList add()函数正在复制我的数据

Java ArrayList add()函数正在复制我的数据,java,arraylist,Java,Arraylist,标题可能有点混乱,所以我将通过代码演示正在发生的事情。我过去使用过ArrayList,所以我要么错过了一些非常明显的东西,要么我认为这与我的Java版本(jdk1.7.0_75/jre1.7.0)有关 对象类: package server.model.objects; public class Objects { public long delay, oDelay; public int xp, item, owner, target, times; public

标题可能有点混乱,所以我将通过代码演示正在发生的事情。我过去使用过ArrayList,所以我要么错过了一些非常明显的东西,要么我认为这与我的Java版本(jdk1.7.0_75/jre1.7.0)有关

对象类:

package server.model.objects;


public class Objects {

    public long delay, oDelay;
    public int xp, item, owner, target, times;
    public boolean bait;

    public static int objectId;
    public static int objectX;
    public static int objectY;
    public int objectHeight;
    public int objectFace;
    public int objectType;
    public int objectTicks;

    public static int getObjectId() {
        return objectId;
    }

    public static int getObjectX() {
        return objectX;
    }

    public static int getObjectY() {
        return objectY;
    }


    public Objects(int id, int x, int y, int height, int face, int type, int ticks) {
        Objects.objectId = id;
        Objects.objectX = x;
        Objects.objectY = y;
        this.objectHeight = height;
        this.objectFace = face;
        this.objectType = type;
        this.objectTicks = ticks;
    }




    public int getObjectHeight() {
        return this.objectHeight;
    }

    public int getObjectFace() {
        return this.objectFace;
    }

    public int getObjectType() {
        return this.objectType;
    }
}

感谢所有的帮助。感谢您的时间。

objectX
是代码中的一个静态变量,这意味着无论何时,只要它作为一个整体绑定到
对象,而不是绑定到任何特定实例,并且在一个地方更改它,它就会在任何地方更改


使其不是静态变量应该可以解决问题。

您需要向我们展示您的
对象
类。我猜
objectX
是一个静态变量。(您还应该遵循Java命名约定,并为类想出比
对象更好的名称)“ArrayList add()函数正在复制我的数据”不,不是。还有别的事,你说得对,乔恩。非常感谢你。我正在做一个开源项目来提高我的技能。谢谢T.J和Jon。Jon Skeet的心理调试技能再次证明是有用的。我如何在这个评论部分投票?
77
77
77
package server.model.objects;


public class Objects {

    public long delay, oDelay;
    public int xp, item, owner, target, times;
    public boolean bait;

    public static int objectId;
    public static int objectX;
    public static int objectY;
    public int objectHeight;
    public int objectFace;
    public int objectType;
    public int objectTicks;

    public static int getObjectId() {
        return objectId;
    }

    public static int getObjectX() {
        return objectX;
    }

    public static int getObjectY() {
        return objectY;
    }


    public Objects(int id, int x, int y, int height, int face, int type, int ticks) {
        Objects.objectId = id;
        Objects.objectX = x;
        Objects.objectY = y;
        this.objectHeight = height;
        this.objectFace = face;
        this.objectType = type;
        this.objectTicks = ticks;
    }




    public int getObjectHeight() {
        return this.objectHeight;
    }

    public int getObjectFace() {
        return this.objectFace;
    }

    public int getObjectType() {
        return this.objectType;
    }
}