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 arguements here");
return true;
}
}
Then I have another method that calls isValidURL in the parent class
public class Child {
Parent parent = new Parent();
public void verifyURL(String url) {
parent.isValidURL();
}
}
Now in the class, the Parentmethod isValidURL()should print the method of the caller, which verifyURL()and its arguments.
Is this possible without reflection? Are there any design patterns that need to be followed?
EDIT: I want to do this because I want to implement the idea in a magazine. In principle, there are many other methods, such as a method verifyURL()that takes different parameters. I would like to have a general log to print it to the console when any methods are called in the "Child" class
source
share