r/java • u/javinpaul • Mar 12 '13
How to make a class Immutable in Java
http://javarevisited.blogspot.sg/2013/03/how-to-create-immutable-class-object-java-example-tutorial.html1
u/mk_gecko Mar 12 '13
Thanks! A very clear write up. Great for people who are learning abou Java classes and objects.
1
1
u/MRH2 Mar 13 '13
JavinPaul, I'll look at your other java pages and use them as reference. I'm working on writing up an explanation of how classes work, but nothing as advanced as singleton, etc. See http://quarkphysics.ca/ICS4U1/unit2/classes.html
By the way, you have two blog sites: javarevisited.blogspot.com and java67.blogspot.com . What's the difference between them?
Finally, I notice in your writing that you tend to leave out small words (the, that, which, ...). Strangely, this doesn't affect the clarity of your writing. If you ever need something written for publication or a conference with correct grammar, I'd be happy to proof read and correct it for you.
3
u/UnspeakableEvil Mar 12 '13
Although it's not a class you're using other than as an example, you may want to update the site to reference StringBuilder rather than StringBuffer - the latter still has its uses in very specific circumstances, but the vast majority of the time StringBuilder is the way to go these days.
It could also be an idea to mention the builder pattern as a way to simplify the creation of immutable objects with a large number of internal fields.
One other suggestion is covering the idea of coupling static constructors with an immutable class - this can allow for caching of common instances of the class (e.g. in the way Integer.valueOf() behaves), with the performance and memory footprint advantages that this can bring.