Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

12
  • 6
    Moreover, final has a special role in multithreaded execution - changing final values would break the Java memory model too. Commented Jul 21, 2010 at 16:47
  • 2
    And a field not declared final should not be declared static. Commented Jul 21, 2010 at 19:34
  • 2
    @Tom: In general that's probably true, but I wouldn't outlaw all static mutable variables. Commented Jul 22, 2010 at 12:37
  • 7
    @Tom: Did you ever read up why singletons are evil? I did! Now I know that they evil only in Java. And only because of the availabilty of a user defined class loader. And ever since I know all this and I don´t use user defined class loader I use singletons without regret. And so does Scala where singleton are a first class language feature — That singletons are evil is is a well known false myth. Commented Jun 10, 2011 at 12:16
  • 4
    @Martin I know that your comment is old, and perhaps your views have changed by now, but I thought I'd just add this: Singletons are evil for reasons that have nothing to do with Java. They add hidden complexity to your code. Additionally, they can make it impossible to unit test without also knowing that n singletons must also be configured first. They are the antithesis of dependency injection. Your team might make the decision that the pitfalls of having hidden complexity don't outweigh the convenience of Singletons, but many teams take the opposite stance for good reason. Commented May 19, 2016 at 16:00