JavaTip : final values can be modified but cannot be reassigned

if I had a Person object and did final Person p = new Person("me"); it means I can’t reassignp to point to another Person object. I can still do p.setFirstName("you");

What confuses the situation is that

final int PI = 3.14;
final String greeting = "Hello World!";

Containers or objects with mutator methods that can alter the internal state of the object are not const just the reference to those objects are final and can’t be reassigned to reference another object.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.