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 8323477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:44:03+00:00 2026-06-08T23:44:03+00:00

I have written the code shown below: public class SiteMapFactory { public static ISiteMap

  • 0

I have written the code shown below:

public class SiteMapFactory {

    public static ISiteMap getSiteMap(Locale loc) {
        ISiteMap returnMap = null;

        if (loc.equals(Locale.US)) {
            returnMap = SiteMap_en_US.getInstance();
        }
        if(loc.equals(new Locale("es","US"))){
            returnMap = SiteMap_en_US.getInstance();
        }
        if(loc.equals(Locale.CANADA)){
            returnMap = SiteMap_fr_CA.getInstance();
        }
        return returnMap;
    }
}

I want to return the same site map for both en_US (English) and es_US (Spanish) of our website. So I am instantiating the US sitemap for both Spanish and English version (a third party vendor is converting our English pages to Spanish). The way the site map is instantiated is using singleton. Singleton object is created as follows:

public class SiteMap_en_US extends SiteMapTree {
    private static SiteMap_en_US m_instance;

    private SiteMap_en_US() {}

    static {
        m_instance = new SiteMap_en_US();
        m_instance.init();
    }

    public static SiteMap_en_US getInstance(){
        return m_instance;
    }

    @Override
    protected void init() {
        //some code
    }
}

My question is: can I reuse the same singleton object twice? Is it a valid way of instantiating the singleton object?

  • 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-06-08T23:44:04+00:00Added an answer on June 8, 2026 at 11:44 pm

    Yes, you can reuse the same singleton object.

    However: If you do this, you should not have to include any special handling within the object to determine which language it is being used for, it should simply behave the same way all the time.

    If you have to make it behave differently, consider creating a subclass of SiteMap_en_US (SiteMap_es_US perhaps) that is derived from SiteMap_en_US and has a small number of behaviors overridden.

    It’s possible to do all sorts of locale checks within the object to determine its behavior, but I highly recommend considering a different approach that’s easier to maintain.

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

Sidebar

Related Questions

I have a simple query in my code (shown below) written by my colleague.
I have written the code shown below. my problem is that I can't touch
I have written is code below, but button isn't shown because i've set FILL_PARENT
Hi I have written code like this @Id @Column(nullable=false) @GeneratedValue(strategy=GenerationType.AUTO) public int getUserID() {
Below is a class I have written in a web application I am building
I have created the alarm as shown below Intent intent = new Intent(this, Areceiver.class);
I have written the below code to validate the value in the string before
I am loading a mapview with annotation. I have written the code as shown
Below, I have written simple code that re-creates problems that have emerged as my
I have written the below code which has a text-field and a button. as

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.