Skip to content

Lesson on Immutability/Mutability? #125

@mikerasch

Description

@mikerasch

This is a topic which is heavily misunderstood. Even from the concept that a record is immutable (yes this is true, but it is not deeply immutable so it causes some confusion).

I think focusing some effort into writing something about this could have some great benefits for newcomers.

They do things like

String foo = "foo";
foo.toUpperCase(); // new string

or

List.of()

or

public record Student(String name, List<String> courses) { }
// Cant modify the fields like student.name = "something";
// but can add to courses, this leads to confusion for newcomers

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions