-3

I am reading the Book O'reilly Functional Programming for Java Developers from Dean Wampler.

On the page 9, It uses an example titled:

"Consider the following example, where a mutable List is used to hold a customer's orders:

public class Customer {

//No setter method

private final List <Order> orders;

public List <Order> getOrders() {return orders;}

public Customer (...) {...}

Ok.

  1. according to the book, if I assign final to a List it means that it will not mutate because it prevents the reassignment of its value.

  2. What its the meaning of (...) & {...}

Thank you very much for the explanation in advance.

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
Marlhex
  • 1,870
  • 19
  • 27
  • 1
    Is there a question in #1? As for #2, the dots just mean that the Customer constructor has some unspecified arguments and some unspecified body. – Eran Sep 19 '17 at 13:20
  • 1
    1: What's the question? 2: They're used as examples; think of it as a cleaner way to say "blah blah blah, this part doesn't matter, since the important part is up above" – Chris Forrence Sep 19 '17 at 13:21

2 Answers2

3

your interpreation is wrong or the book made a mistake:

this

private final List <Order> orders =....;

means only that you can not change that reference like doing somewhere later

orders = new ArrayList<>();

but the list can for sure mutate since you can put, remove and truncate its content

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
  • to clarify ,only the `final` has the meaning explained. the private has nothing to do with it – Itamar Jan 08 '18 at 13:13
1

according to the book, if I assign final to a List it means that it will not mutate because it prevents the reassignment of its value.

Yes 'private final' means you cant change the value. Which mean you need to re-create it on change. This makes the class immutable by using a mutable data structure.

Edit: to clarify, the list is mutable. The class is immutable, because the list is private and final and there is no setter. Which makes the list read only.

What its the meaning of (...) & {...}

Three dots usually represent a code that is irrelevant to the example.

The code us an example of Costumer construction.

In this case (...) Is the function signature arguments (which mean that there are ones, but it doesn't matter for the example.

{...} represent the function body, Which again, irrelevant to the example.

Itamar
  • 1,601
  • 1
  • 10
  • 23