I'm looking at a way to add some tracing diagnostics to some legacy Java code. By legacy in this sense I mean I cannot change any of the methods. If we consider the following objects:
public class ClassIOwnAndCanChange {
public static void main(String[] args) {
// store my object here that I want to make
// available in LegacyClassA and B
myMethod("foo", 100);
}
}
public class LegacyClassA {
// method I cannot change
public void myMethod(String name, int timer) {
//want to get my 'injected' object here so that I can,
//for instance, time this method
methodCallThatTakesSomeTime("some param");
}
}
public class LegacyClassB {
// method I cannot change
public void methodCallThatTakesSomeTime(String name) {
// want to get my 'injected' object here for
// diagnostic reasons
}
}
I own A and I would like to make an object available in B and C. What is the right way to do this in Java without changing the method that A calls on B and the method that B calls on C?
methodOfA,methodOfBetc. Seems to me from the title a static member may do the job, but it is possible I misunderstand you