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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:46:20+00:00 2026-06-08T05:46:20+00:00

My java is a bit rusty, and I have to implement a solution for

  • 0

My java is a bit rusty, and I have to implement a solution for this problem.

Given in A.java where:

public class A implements Cloneable{
  protected DataStorage Y = new DataStorage();

  public A(DataStorage X, about 20 other inputs of different Object types){
   this.Y=X;
  }

  public static DataStorage getData(){
   return this.Y;
  }
}

My goal in another file ServletA.java where I want to retrieve the object Y or X. By doing a static call from A.java class… does it work or is there a better way?

public class ServletA{
  DataStorage Z = A.getData();
}

Note: Yes, this doesn’t compile, but is there a solution around it?

My constraints that I have for the solution:

  • to make minimal changes to A.java because it is legacy codebase
  • there are many 20+ inputs for the A() constructor which is a nightmare
  • and my architect doesnt want to touch it either by changing A into an abstract class
  • cannot create an instance of A in ServletA.java

EDIT1: my question is if there is a solution to access X from ServletA.java WITHOUT creating an instance of A in ServletA.java. The above code is an example to show that i have thought of a method, but it doesnt work.

EDIT 2: if you want to downvote, please ask me for clarifications as courtesy. thanks!

  • 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-08T05:46:22+00:00Added an answer on June 8, 2026 at 5:46 am

    If you only have one instance of A you should use the singleton pattern.
    Your ServletA code should be something like

    public class ServletA {
      DataStorage Z = A.getInstance().getData();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a bit rusty on my Java. I have an array with several
My Java is a bit rusty, and I am sure I am doing this
I am a bit rusty in my Java, and this is my first time
This question is about 64-bit Java apps in general, although I came upon it
What is the maximum file size 32 bit java can access? Is this architecture
This is my simple program: public class Test { public static Object obj =
I'm pretty new to Android but I have some experience (and a bit rusty
I have a bit of Java I want to edit (it is a Minecraft
My Java is very rusty and I'm having a bit of a headache here.
This is 64-bit Windows 7 Enterprise and 64-bit Java 7: java version 1.7.0_04 Java(TM)

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.