jeudi 12 janvier 2023

How to get the method's parameter expression stack or string representation?

I am writing a method for debugging and metrics capturing, such that:

void capture(Object value, String debugName) {
  System.out.println("captured " + debugName + " with value " + value);
}

and calling it with:

capture(foo.bar(), "foo.bar");

Is there any way to get the value expression string directly, so I don't need to pass the debugName? Something like:

void capture(Object value) {
  System.out.println("captured " + getStack(value) + " with value " + value);
}




Aucun commentaire:

Enregistrer un commentaire