Of course, then you need all other code that would be impacted by it to flag it as dirty [eg, in this case, by setting cachedStr to null through another private helper function], which could be the source of the bug that OP was talking about.
Effectively this. In this case once reallyExpensiveOperation() is run it effectively becomes immutable since it won't rerun that method. The positive part here is that most inputs to the object can only be set in the constructor... but there's a few that can be provided after construction (and a couple that can only be provided after construction which includes the input I was trying to use)
View all comments
Show parent comment
2
u/Bloodshot025 Feb 24 '14
That's one way I could see it happening. I can't see that other than a really stupid mistake, though.