Java — Final VS Immutability | Code Factory

Code Factory
1 min readMay 16, 2020

--

Index Page : Link

Donate : Link

  • If you don’t want to perform reassignment for the variable then it is a final.
  • If you don’t want to perform any changes in the object then it is a immutable.
final StringBuffer sb = new StringBuffer("Code");
sb.append("Factory");
System.out.println(sb); // CodeFactory
sb = new StringBuffer("Hello"); // CE : cannot assign a value to final variable sb

Which of the following are meaningful?

  1. final variable
  2. final object X
  3. Immutable variable X
  4. Immutable object

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response