aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Should the Singleton instance be a final variable? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Should the Singleton instance be a final variable?" Watch "Should the Singleton instance be a final variable?" New topic
Author

Should the Singleton instance be a final variable?

Eric Kizaki
Greenhorn

Joined: Jan 21, 2011
Posts: 12

I am doing coding exercises on Bert Bates's OCP Java SE 6 Programmer Practice Exams book. One of the questions is to write a singleton class (pg. 150).
Should the singleton instance be a final variable?



OCPJP 6
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

Did you try changing the declaration for that variable to include "final"? What happened then?
Eric Kizaki
Greenhorn

Joined: Jan 21, 2011
Posts: 12

I had to rewrite a lot of it. Now I think it won't be changed.

Javin Paul
Ranch Hand

Joined: Oct 15, 2010
Posts: 276


Hi Dude,

I don't think there is a need to make single instance as final but while writing Singleton class its worth noting to implement double checking of Singleton instance. e..g




Thanks
Javin


http://javarevisited.blogspot.com - java classpath - Java67 - java hashmap - java logging tips java interview questions Java Enum Tutorial
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3670

And welcome to CodeRanch, Eric Kizaki


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Should the Singleton instance be a final variable?
 
Similar Threads
Static Variables and Methods
Question regaring Singleton.
singleton
Singleton
2 different types of singleton