| « Page Not Found | Trouble With Founders, the Lost Candidate, and More » |
It started when David tried to access a Singleton and got a null-pointer exception. Then he noticed some bugs where the Singleton had inconsistent state. And then he looked at the code…
public class KpiService { private static KpiService instance = null; public static KpiService getInstance() { return instance; } public KpiService() { instance = this; } /* SNIP */ }
|
What's wrong with that? It's easily discerned that the this in this singleton refers to this this from the singleton's point of view. From all other points of view, you should not be accessing that this, this this or the this, but the singleton via its getInstance, or pseudo-this.
See? This is not so hard to understand! |
| « Page Not Found | Trouble With Founders, the Lost Candidate, and More » |