Created
April 11, 2011 22:18
-
-
Save casualjim/914495 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collection.JavaConversions._ | |
trait Base { | |
def invoke(curr: String) { | |
println("invoking: " + curr) | |
Thread.currentThread.getStackTrace.foreach(st => println("className: " + st.getClassName + " methodName: " + st.getMethodName )) | |
} | |
} | |
class Top extends Base { | |
invoke("top") | |
} | |
class Hello extends Top { | |
invoke("hello 1") | |
invoke("hello 2") | |
} | |
/* | |
Apparently the key is to find the first <init> method after the call we want to check | |
scala> new Hello | |
invoking: top | |
... garbage ... | |
className: Top methodName: invoke | |
... potentially more method calls ... | |
className: Top methodName: <init> | |
className: Hello methodName: <init> | |
... garbage ... | |
invoking: hello 1 | |
... garbage ... | |
className: Top methodName: invoke | |
... potentially more method calls ... | |
className: Hello methodName: <init> | |
... garbage ... | |
invoking: hello 2 | |
... garbage ... | |
className: Top methodName: invoke | |
... potentially more method calls ... | |
className: Hello methodName: <init> | |
... garbage ... | |
res0: Hello = Hello@5dcdd76a | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment