Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4597514
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:16:04+00:00 2026-05-21T23:16:04+00:00

the page at http://www.javaworld.com/javaworld/jw-04-2003/jw-0425-designpatterns.html?page=5 says that code like this: public final static Singleton INSTANCE

  • 0

the page at http://www.javaworld.com/javaworld/jw-04-2003/jw-0425-designpatterns.html?page=5 says that code like this:

public final static Singleton INSTANCE = new Singleton();

automatically employs lazy instantiation.

I want to verify if

1) all compilers do this, or is it that the compiler is free to do whatever it wishes to

2) and since c# does not have the “final” keyword, what’s the best way to translate this into c# (and at the same time it should automatically employ lazy instantiation too)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T23:16:05+00:00Added an answer on May 21, 2026 at 11:16 pm

    Yes. The static initializer is guaranteed to run before you are able to access that INSTANCE. There are two negatives with this approach:

    1. If an error occurs within the Singleton’s construction, then the error is a little harder to debug (“Error in initializer”).
    2. On first use of the class, that object will be instantiated. If you did the locking approach, then it would not be instantiated until it was needed. However, being that the example is a singleton, then this is not a problem at all, but it could be a drag on an unused, yet lazily instantiated piece of code elsewhere that is not a singleton.

    The translation for C# is readonly instead of final.

    In my opinion, this is still vastly preferable to the secondary approach (synchronized/locked, checked instantiation within the a static getter) because it does not require any synchronization code, which is faster, easier to read and just as easy to use.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am reading this page http://www.cplusplus.com/doc/tutorial/exceptions.html it says if i write function() throw(); no
On this test page: http:// www.onebagoneearth.com/ Products-test , where it says oboe love series,
in this page: http://www.studiokhalid.com/test/jquery/2.html I am trying to use a simple Jquery Coda slider
on this page: http://www.shutterfly.com/documentation/OflyCallSignature.sfly it says once you generate a hash you then: convert
On this page: http://www.ubhape2.com/formhelp.html I have 3 file uploads. I have it set now
This sample page: http://www.downloadformsindia.com/Income-Tax-Forms/challan-281.html?task=view has H1 text of Challan 281. But it's not getting
Looking at this page: http://www.mikeash.com/pyblog/friday-qa-2010-12-31-c-macro-tips-and-tricks.html I found this snippet of code with ^{ ...
This web page http://www.w3schools.com/ASP/prop_sessionid.asp states that a session ID is generated on the ServerSide.
I have a web page http://www.maryveale.com/sculpture/index.html that loads a js at /media/js/bill-studio.js that causes
Please check this page: http://www.playtrickz.com/basic/basic.html with Firebug. Please tell me why the #pagefooter is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.