jeudi 7 octobre 2021

How to get values of current method without using reflection in java

I would like to create new annotation for logging method name and method's parameter value.

I'm using the below code to retrieve the method parameter information without using 'java reflection'(because its too costly).

    public void method1(String param1) {

    Method method = new Object() {}.getClass().getEnclosingMethod();

    System.out.printf(method.getName() + " : ");

    Parameter[] parameters = method.getParameters();
    for (Parameter parameter : parameters) {
        System.out.printf(parameter.toString());
    }
}

its output is :

method1 : java.lang.String arg0

Here I'm getting parameter type and its name. I want to retrieve parameter value

I had tried @Loggable annotation of https://aspects.jcabi.com/ and that is not working.

@Loggable references: (https://aspects.jcabi.com/annotation-loggable.html) (https://aspects.jcabi.com/apidocs-0.22.6/com/jcabi/aspects/Loggable.html)





Aucun commentaire:

Enregistrer un commentaire