N
N
Nikita2018-01-30 11:57:52
Java
Nikita, 2018-01-30 11:57:52

Why can the value of final be changed?

I understand that this block of code acts as a counter, but I don't understand why
5a702ff7f1471694563919.pngGjxt

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Mikhail Ketov, 2018-01-30
@Dugayoyo

It cannot be changed (you cannot change the link). And in this example, it is not changed, but the incremented value of counter is written into it.

B
Bonce, 2018-01-31
@Bonce

So counter is not final. Here final is the value of id.

M
MaxLich, 2018-02-01
@MaxLich

You cannot change final fields after the object is created, but you can and should change them (set values ​​for them) during the creation of the object. So there are no problems here. During the creation of the object, before calling the constructor, all fields are initialized, including this id field.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question