Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Caller method and line  RSS feed

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Do you know what is the fastest way to find the caller class and method/ Line?

I know two approaches:
- Printing the thread trace
- New throwable then getting info from it..

Is there another way? What is the best from performance point of view?

Thanks
 
Sheriff
Posts: 21288
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thread.currentThread().getStackTrace() should be enough.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!