Search code examples
javafinal

If a non-primitive attribute is declared as final can I make assumptions about its state (count on a given state in a given moment)?


Assuming its reference its exposed by a getter method.

Hi, I am new here. I am first year university student doing a bachelor in informatics. In one of my weekly assignments I came upon this question, which I don't know the asnwer to. Could someone please help me??


Solution

  • Simple answer: No. Final means that you cannot change object to which the reference points, but it says nothing about that object's internal state.

    In other words - you cannot modify final reference, but you can modify the object it references.