| 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
|
|
|
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]
|
 |
 |
|
|
subject: Should the Singleton instance be a final variable?
|
|
|