일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- Struts
- tomcat
- jsr 296
- jQuery
- JSON
- MySQL
- sencha touch
- rowspan
- PLSQL
- WebLogic
- Spring
- oracle
- swingx
- node.js
- appspresso
- dock
- iBATIS
- 전자정부프레임워크
- MFC
- PHP
- JDOM
- Eclipse
- Google Map
- ibsheet
- 가우스
- phonegap
- 선택적조인
- GPS
- Android
- Ajax
Archives
- Today
- Total
Where The Streets Have No Name
호출한 메소드명 알아내기 본문
/**
* Get method name within the current call stack. The top most has offset 0 (that is this method), the next has offset 1
* (that is the caller of this method), and so on.
* Usage: <code>getMethodName(new Throwable())</code>.
*
* @param full If true, not only the method name but the complete package and class string as prefix
* (e.g. "org.happy.tools.Utils.getLucky")
* @param offset Index offset from top most stack trace element. If the caller wants to get the name of the
* method of its caller, the offset has to be 2.
* @return Method name of the top StackTraceElement.
*/
static public String getMethodName(final boolean full, final int offset) {
String result = null;
final Throwable t = new Throwable();
if (t != null) {
final StackTraceElement[] stes = t.getStackTrace();
if (stes != null && stes.length > 0) {
if (full) {
result = stes[offset].getClassName().concat(".").concat(stes[offset].getMethodName());
} else {
result = stes[offset].getMethodName();
}
}//else: StackTraceElement unavailable
}//else: input unavailable
return result;
}//getMethodName()
사용법) System.out.println(HelloWorld.getMethodName(true,1)); //이부분이 코딩된 메소드명이 출력됨
public String getMethodName() {
String result = null;
final Throwable t = new Throwable();
if (t != null) {
final StackTraceElement[] stes = t.getStackTrace();
if (stes != null && stes.length > 0) {
result = stes[1].getClassName().concat(".").concat(stes[1].getMethodName());
}//else: StackTraceElement unavailable
}//else: input unavailable
return result;
}//getMethodName()
* Get method name within the current call stack. The top most has offset 0 (that is this method), the next has offset 1
* (that is the caller of this method), and so on.
* Usage: <code>getMethodName(new Throwable())</code>.
*
* @param full If true, not only the method name but the complete package and class string as prefix
* (e.g. "org.happy.tools.Utils.getLucky")
* @param offset Index offset from top most stack trace element. If the caller wants to get the name of the
* method of its caller, the offset has to be 2.
* @return Method name of the top StackTraceElement.
*/
static public String getMethodName(final boolean full, final int offset) {
String result = null;
final Throwable t = new Throwable();
if (t != null) {
final StackTraceElement[] stes = t.getStackTrace();
if (stes != null && stes.length > 0) {
if (full) {
result = stes[offset].getClassName().concat(".").concat(stes[offset].getMethodName());
} else {
result = stes[offset].getMethodName();
}
}//else: StackTraceElement unavailable
}//else: input unavailable
return result;
}//getMethodName()
사용법) System.out.println(HelloWorld.getMethodName(true,1)); //이부분이 코딩된 메소드명이 출력됨
public String getMethodName() {
String result = null;
final Throwable t = new Throwable();
if (t != null) {
final StackTraceElement[] stes = t.getStackTrace();
if (stes != null && stes.length > 0) {
result = stes[1].getClassName().concat(".").concat(stes[1].getMethodName());
}//else: StackTraceElement unavailable
}//else: input unavailable
return result;
}//getMethodName()