Do write-only properties have practical applications?

My first reaction to this question was: “What about the java.util.Random#setSeed method?”

I think that write-only properties are useful in several scenarios. For example, when you don’t want to expose the internal representation (encapsulation), while allowing to change the state of the object. java.util.Random is a very good example of such design.

Leave a Comment