4
I wanted to know if there is any way to get the class that called a method within that method. For example:
public class A {
public void metodoA() {
B.metodoB();
}
}
public static B {
public void metodoB() {
//Aqui, de alguma forma, pegar a classe A, quando ela chamar
}
}
Is there such a possibility in Java or I would need to send the class as a parameter to the metodoB
?
B.metodoB(this.getClass());
?– user28595
@Articuno as I finished in the question, this is the only way? There would be no way I ever catch from inside the
metodoB
?– Felipe Avelar
What version of Java? Have JEP-259 in Java 9.
– Renan Gomes
@Renan is version 8
– Felipe Avelar
You probably want to have different behaviors for each caller. Look for Strategy and hook method One of the two or the two together should solve your problem
– Gnk