I want to find the line number of a code dynamically. How can this be done?
public static void main(String[] args) {
System.out.println("This Line Number is : ????");
}
I want to find the line number of a code dynamically. How can this be done?
public static void main(String[] args) {
System.out.println("This Line Number is : ????");
}
you can get line number from getStackTrace()[]
public static void main(String[] arg)
{
System.out.println("This Line Number is : "+Thread.currentThread().getStackTrace()[1].getLineNumber());
}
Is it compulsory to use your own log functions? It will be easier to use log4j or any other "standard" log libray