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!