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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
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: 18887
    
    8

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: 281


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: 3855

And welcome to CodeRanch, Eric Kizaki


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Should the Singleton instance be a final variable?