Originally posted by Jesper Young:
To make an immutable class, you simply have to make sure that you don't provide any methods in the class that alter the state of the object after initialization.
You can't wake a person who is <b><i>pretending</i></b> to be asleep.<br />Like what <b>"it"</b> does not like - <i> Gurdjieff </i>
Originally posted by Rajah Nagur:
But cannot a class state be altered by using Reflection API?
Tony Morris
Java Q&A (FAQ, Trivia)
Originally posted by Tony Morris:
Perhaps it's time for a detailed FAQ.
Originally posted by Tony Morris:
You create a type contract (read: interface) that declares that all operations are referentially transparent (hint: google search term). Since referential transparency generally applies to functional programming (FP), I will show you a simplified version of the translation from OO to FP.
Any OO "method" has a direct analogous function. Simply, take the type that it is declared on and add that type as the first parameter to a function.
Here is a quick (because I've said it enough times already) example:
Given String.charAt(int), the translation to a function is (very roughly):
char charAt(String, int).
This function is referentially transparent. In fact, all operations on type String can be said to be referentially transparent, therefore, we (well you might but I don't) say it is immutable. I don't use this term because of its association with informality, marketing literature and established but ill-formed beliefs.
Perhaps it's time for a detailed FAQ.
Tony Morris
Java Q&A (FAQ, Trivia)
Originally posted by Tony Morris:
in Java is impossible to prove referential transparency.
Sorry, Tony, but that's just prejudicial twaddle.
Tony Morris
Java Q&A (FAQ, Trivia)
Tony Morris
Java Q&A (FAQ, Trivia)
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |