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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:36:25+00:00 2026-05-27T12:36:25+00:00

Given: File f = new File(test.txt); this way, each time i create a reference

  • 0

Given:

File f = new File("test.txt");

this way, each time i create a reference to the file “text.txt”, i get a different File object.

I need that if the file is the same, then I get the same File object.
(To be precise and coherent with the example, it is the canonical path that has to be the same, but since this is just an example, i don’t want to go in deep with files identities)

It can be quite easily implemented with a static getInstance that tests the previously created File instances, stored in a Collection and returns the stored one if present.

This seems to be a “more general singleton pattern”, where singleton means one instance per application, while here we have one instance each distinct identity (in the example, each file path will have only one File object).

The question is, since singleton is well documented (and perhaps over-documented) is this pattern “described” and standardized too?

(This is exactly what happens in certain jvm implementations for Integers<128 for optimization purposes and not to rely on).

  • 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-27T12:36:26+00:00Added an answer on May 27, 2026 at 12:36 pm

    It seems it’s called a Multiton, or a registry of singletons. I don’t think it’s as well documented as a sigleton, but, as you noticed, it’s really a more general version of a singleton, and shares the same set of strengths and weaknesses.

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

Sidebar

Related Questions

Given file names like these: /the/path/foo.txt bar.txt I hope to get: foo bar Why
Hi I am trying to read a plain text file named test.txt from my
I have this code: File.foreach(testfile.txt) { |line| print line } lines = File.readlines(testfile.txt) lines.each
Given the following Java code for generating a binary file: DataOutputStream out = new
I wrote this script which counts occurrences of particular pattern in a given file.
How can I write text files using WScript I'm really new on this that's
I use this trivial function to calculate the CRC checksum of a given file:
When using split windows in VIM, sometimes I create new split of a file
public StormAnalysis(){ try { fScanner = new Scanner(new File(tracks1949to2010_epa.txt)); while(fScanner.hasNextLine()){ System.out.println(fScanner.nextLine()); } } catch
given the following text file: Find all HeaderText=, Subfolders, Find Results 1, Entire Solution

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.