0

I'd like, given a certain object, to know where its class definition came from for logging purposes. Very likely this object will be anonymous inner types therefore the filename:line could help to investigate where a certain call is coming from.

  Proxy.newProxyInstance(this.getClass().getClassLoader(),
                           new Class[] { MyClass.class },
                           new InvocationHandler() {

 @Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                  // Transparent proxy
                 final Object result = method.invoke(delegator, args);                    
                 System.out.println("Args[0] is of type " 
                                    + args[0].getClass().getName() 
                                    + " defined in "...);
});
Pietro
  • 13
  • 4
  • 1
    Perhaps this is of help: [How to get the line number of a method?](https://stackoverflow.com/questions/12834887/how-to-get-the-line-number-of-a-method) – Jeppe Feb 20 '19 at 08:22
  • You could somehow fiddle with `Thread.currentStackTrace(`)` – Lino Feb 20 '19 at 08:23
  • Yeah, Lino's suggestion was the quickest way to get where I wanted to – Pietro Feb 25 '19 at 08:55

0 Answers0