Results 1 to 3 of 3
Thread: caller info
- 04-02-2010, 06:07 PM #1
caller info
Class A creates an object of Class B and uses that object to instantiate a method C. How can i tell inside method C that 'this' was called by A?
Inside class A:
B bbb = new B();
bbb.doSomethingClever();
Inside class B:
inside doSometihngClever () {
I got called from class A ... <-- how can i get this information?
}
- 04-02-2010, 06:18 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,604
- Blog Entries
- 7
- Rep Power
- 17
Maybe the following can be of any help:
Note that the JVM is free to skip StackTraceElements (thanks to call optimizations).Java Code:public class AAA { public static void main(String[] args) { new BBB().method(); } } class BBB { public void method() { Exception ex= new Exception(); ex.fillInStackTrace(); StackTraceElement[] ste= ex.getStackTrace(); for (int i= 0; i < ste.length; i++) System.out.println(ste[i].getMethodName()+" in "+ste[i].getClassName()+" at line "+ste[i].getLineNumber()); } }
kind regards,
Jos
- 04-02-2010, 06:28 PM #3
Similar Threads
-
Best way to do a pop-up 'info bubble'
By lightstream in forum AWT / SwingReplies: 2Last Post: 01-27-2009, 07:39 AM -
INFO About JDK1.6
By ravi in forum New To JavaReplies: 2Last Post: 11-03-2008, 02:30 PM -
Looking for some info.
By Ragster in forum JDBCReplies: 2Last Post: 01-17-2008, 05:19 PM -
Getting Header Info
By Java Tip in forum Java TipReplies: 0Last Post: 11-26-2007, 01:30 PM -
JVM Info
By kishi in forum Advanced JavaReplies: 0Last Post: 11-16-2007, 01:44 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks