Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Should the Singleton instance be a final variable?

 
Eric Kizaki
Greenhorn
Posts: 12
Eclipse IDE Google Web Toolkit Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?


 
Paul Clapham
Sheriff
Pie
Posts: 20955
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try changing the declaration for that variable to include "final"? What happened then?
 
Eric Kizaki
Greenhorn
Posts: 12
Eclipse IDE Google Web Toolkit Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had to rewrite a lot of it. Now I think it won't be changed.

 
Javin Paul
Ranch Hand
Posts: 295
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to CodeRanch, Eric Kizaki
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic