Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

immutable objects vs classes

 
Don Bosco
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any difference between Immutable objects and classes?
according to my understanding from mock tests
Math is an immutable class.
objects of Double, Integer etc., are immutable objects.
 
chintan desai
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Don Bosco:
Is there any difference between Immutable objects and classes?
according to my understanding from mock tests
Math is an immutable class.
objects of Double, Integer etc., are immutable objects.

According to my understanding Math Class is final class so it can not be subclassed or extended.
Objects of Doubl,Integer Etc. (Wrapper Classes) are immutable objects so their objects can not be changed.
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to change the state of a class? I do not think so. Math is a utility class: uninstantiable and full of static useful methods.
A immutable class should produce immutable instances.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic