Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
blu3r4y opened this issue Jul 3, 2022 · 0 comments

Comments

@blu3r4y
Copy link
Owner

blu3r4y commented Jul 3, 2022

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]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant