Skip to content

Think about removing generics and collections to be more beginner-friendly #1

Open
@blu3r4y

Description

@blu3r4y

This specific examples might show some confusion:

// ./java/M08_PassByObjectReference.java#L4-L20

static void replace(List<Integer> numbers) {
    numbers = Arrays.asList(42, 43, 44);
}
 
static void append(List<Integer> numbers) {
    numbers.add(42);
}
 
public static void main(String[] args) {
    List<Integer> oneTwoThree = new LinkedList<>(Arrays.asList(1, 2, 3));
 
    replace(oneTwoThree);
    System.out.println(Arrays.toString(oneTwoThree.toArray()));  // [1, 2, 3]
 
    append(oneTwoThree);
    System.out.println(Arrays.toString(oneTwoThree.toArray()));  // [1, 2, 3, 42]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions