Values & References10 / 16
Up next

Pass-by-value of a reference

import java.util.ArrayList;
import java.util.List;

class Main {
    // the reference is copied, but it still points at the caller's list
    static void addZero(List<Integer> items) {
        items.add(0);
    }

    public static void main(String[] args) {
        var nums = new ArrayList<>(List.of(1, 2, 3));
        addZero(nums);
        System.out.println(nums);
    }
}
What you're solving

the callee mutates the same object