---
title: "Comment by Mark on \"Variables And Mutability In Rust\" | Hashnode"
description: "I think it&#39;s useful to highlight that this is a much stronger type of immutability than e.g. Java&#39;s final , or equivalents in many languages. If in Java"
url: "https://hashnode.com/posts/variables-and-mutability/5f65008167d51d3b5d47980b/comment/5f66238e6dfc523d0a893514"
---

[Discussion](https://hashnode.com/posts/variables-and-mutability/5f65008167d51d3b5d47980b)

Comment [Variables And Mutability In Rust](https://hashnode.com/posts/variables-and-mutability/5f65008167d51d3b5d47980b)

[Mark](https://hashnode.com/@mverleg)

[Sep 19, 2020](https://hashnode.com/posts/variables-and-mutability/5f65008167d51d3b5d47980b/comment/5f66238e6dfc523d0a893514)

I think it's useful to highlight that this is a much stronger type of immutability than e.g. Java's `final`, or equivalents in many languages.

If in Java we make a list:

```
final var list = new ArrayList<Integer>();
```

we cannot reassign it:

```
list = new ArrayList<Integer>();
```

but we can change it just fine in other ways:

```
list.add(1);
list.add(2);
list.clear();
```

Rust's `Vec` is a quite similar datatype Java's `ArrayList`:

```
let list = Vec::new();
```

but we cannot change it at all:

```
list.push(1);
list.push(2);
list.clear();
```

gives:

```
error[E0596]: cannot borrow `list` as mutable, as it is not declared as mutable
```

We might say that Java (and most others) has shallow immutability, while Rust's is deep.

There are some caveats though, mostly `RefCell`, `Mutex` and `RwLock`.

[Eduardo Flores](https://hashnode.com/@edfloreshz)

[Sep 19, 2020](https://hashnode.com/posts/variables-and-mutability/5f65008167d51d3b5d47980b/comment/5f66238e6dfc523d0a893514#reply-5f664cfa35d6463d2b5f866f)

Thanks for your comments, I will make an article about smart pointers in the future where I will talk more about mutability.
