Immutable Class

suggest change

Versions

Java SE 1.0, Java SE 1.1, Java SE 1.2, Java SE 1.3, Java SE 1.4, Java SE 5, Java SE 6, Java SE 7, Java SE 8, Java SE 9 (Early Access)

Introduction

An immutable object's state does not change after the object has been initialized. String is an immutable class: once created, the character sequence of that instance never changes.

Remarks

Some immutable classes in Java:

  1. java.lang.String
  2. The wrapper classes for the primitive types: java.lang.Integer, java.lang.Byte, java.lang.Character, java.lang.Short, java.lang.Boolean, java.lang.Long, java.lang.Double, java.lang.Float
  3. Most enum classes are immutable, but this in fact depends on the concrete case.
  4. java.math.BigInteger and java.math.BigDecimal (at least objects of those classes themselves)
  5. java.io.File. Note that this represents an object external to the VM (a file on the local system), which may or may not exist, and has some methods modifying and querying the state of this external object. But the File object itself stays immutable.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents