티스토리 뷰
현재 메소드명 알아내기
Java 1.4
new Exception().getStackTrace()[0].getMethodName();
Java 1.5
StackTraceElement[] elements = Thread.currentThread().getStackTrace();
for(StackTraceElement element : elements) {
boolean doNext = element.getMethodName().equals([Method명]);
if(doNext) {
System.out.println(element.getMethodName());
return;
}
}
* 현재 Class와 MethodName 출력
StackTraceElement[] stacks = new Throwable().getStackTrace();
StackTraceElement currentStack = stacks[0];
System.out.println("Class : " + currentStack.getClassName());
System.out.println("Method : " + currentStack.getMethodName());
* 바로전의 Class와 MethodName 출력
StackTraceElement[] stacks = new Throwable().getStackTrace();
StackTraceElement beforeStack = stacks[1];
System.out.println( "before Class : " + beforeStack.getClassName() );
System.out.println( "before Method : " + beforeStack.getMethodName() );
* 호출된 StackTrace 갯수
StackTraceElement[] stacks = new Throwable().getStackTrace();
System.out.println("stacks size : " + stacks.length);
'Language > Java' 카테고리의 다른 글
Java 코딩 규칙 (0) | 2018.01.08 |
---|---|
[Java] Java 버전 분류 (0) | 2016.12.20 |
[Java]Exception 발생시키기 (0) | 2015.04.02 |
[Java]System.arraycopy (0) | 2015.01.23 |
[Java]정규표현식 (0) | 2015.01.06 |
- Total
- Today
- Yesterday
- php
- Codable
- Spring
- Xcode
- github
- docker
- tomcat
- android
- git
- cocoapods
- windows10
- ubuntu
- go
- SWIFT
- enum
- war
- nodejs
- Java
- Kotlin
- golang
- intellij
- CentOS
- centos8
- Gradle
- Linux
- rxswift
- Python
- Windows
- MySQL
- ios
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |