Values & References11 / 16
Up next

Reassigning a parameter is local

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

class Main {
    static void replace(List<Integer> items) {
        // pointing the local name at a new list breaks the link
        items = new ArrayList<>(List.of(9, 9, 9));
    }

    public static void main(String[] args) {
        var nums = new ArrayList<>(List.of(1, 2, 3));
        replace(nums);
        // the caller's list is untouched
        System.out.println(nums);
    }
}
What you're solving

a new binding does not reach the caller