You cannot do that in Java. The only way to get line number is by
creating a Throwable object and then extracting the stack trace. You
cannot find the line number at compile time.
Regards,
KB
Charles wrote:
Is there a way to obtain the line number in my code? For example:
1 public class MyClass {
2 int a = 5;
3 System.out.println("Integer variable a was set on line number: " + x);
4 etc.
Where x is equal to '2'.
How can I obtain 'x' ?
Thanks.
--
------------------------------------------------------------------------
This email is certified to be Spam free by Spam Marshall
You don't pay to get spam, why pay to clean it?
Visit
http://www.spammarshall.com to create an account for free
<http://www.spammarshall.com>
------------------------------------------------------------------------