Let's say I have a class with a method like below
public class Parent {
public boolean isValidURL() {
System.out.println("print the name of the caller method and the method's arguements here");
//pls ignore the return true below. just an eg.
return true;
}
}
I then have another method that calls the isValidURL in the parent class
public class Child {
Parent parent = new Parent();
public void verifyURL(String url) {
parent.isValidURL();
}
}
Now in the Parent
class the method isValidURL()
should print the caller method which is verifyURL()
and its arguments.
Is that possible without reflection? Are there any design pattern that needs to be followed?
EDIT:
I want to do this because I want to implement the idea on a logger. Basically, there are many other methods like verifyURL()
method accepting different parameters. I'd like to have a common logger to print the it on the console when any methods in the `Child' class is called