mardi 26 janvier 2021

How to automatically print all parameter values of Java function at runtime

I want to print automatically all the parameter values of my functions at runtime.

Just imagin that I have the following two methods:

public void doAction(String firstParam, String SecondParam) {
    Util.printAllParameter(this);
}

public void doAction(String firstParam) {
    Util.printAllParameter(this);
}

If I call to this functions:

doAction("a", "b"); --> Desired result: Print "a, b"

doAction("a"); --> Desired result: Print "a"

I don't want something like this (This is not reusable, it is static):

System.out.println(firstParam + "," + SecondParam);

I need a reusable method that I can use in different functions with different number of parameter. I want to call a function like "Util.printAllParameter()" and then print all the parameters.

Thanks in advance.





Aucun commentaire:

Enregistrer un commentaire