ITeye博客

取得JAVA下的__LINE__

luckfox · 2011-05-13 13:35 · 编程语言 · Markdown


public class Test10
{
    public static void main(String args[])
    {
        System.out.println("This is " + getLineInfo());
    }
 
    public static String getLineInfo()
    {
        StackTraceElement ste = new Throwable().getStackTrace()[1];
        return ste.getFileName() + ": Line " + ste.getLineNumber();
    }
}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。