Showing posts with label Core Java Tips and Tricks. Show all posts
Showing posts with label Core Java Tips and Tricks. Show all posts

Thursday, May 29, 2008

Miscellaneous Java Code


Fetching Line Number in Java Code

1.
new Throwable()).getStackTrace()[0].getLineNumber()

2.

StackTraceElement[] st = Thread.currentThread().getStackTrace();
int lineNumber = st [st.length-1].getLineNumber();

Getting a stack trace can be slow. Using this to do logging can adversely effect the performance of an application.