A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Java in General
Joined: Jun 15, 2006
Jan 02, 2007 02:57:00
how can make a class Immutable?
author and iconoclast
Joined: Jul 08, 2003
Jan 02, 2007 05:38:00
Very simply, don't provide any way to modify any of the member variables. It's that simple. Make sure they're all private, and preferably final, and don't change them after the constructor.
[Jess in Action]
Don't get me started about those stupid
subject: class Immutable
Is the Math class considered immutable?
How to make a class immutable??????????
equals() and ==
Math class immutable
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013