Question on Java Object References

I have created 2 mechanisms called wrist and elbow, which I am implementing into a subsystem called arm.

Just to be clear, I am not using CommandBased, so when I say subsystem, I am not referring to a WPILib subsystem.

I am wondering if the way I am referencing the two mechanisms in my arm class will create a copy of the wrist and elbow objects, or reference them directly. Here are the relevant snippets of code.

in robotInit()

elbow = new Elbow(CAN.kElbow);
wrist = new Wrist(CAN.kWrist);
arm = new Arm(elbow, wrist); 


    private Elbow elbow;
    private Wrist wrist;
    public Arm(Elbow elbow, Wrist wrist) {
        this.elbow = elbow;
        this.wrist = wrist;

Java always passes objects as references so you don’t need to worry about copies

^^ This. There are no explicit pointers in Java; everything except primitive types are handles/references to objects. Assigning the value of one object to another copies the handle, it does not create a copy of the object.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.