Mysterious line in stack trace

后端 未结 1 1726
眼角桃花
眼角桃花 2021-02-20 10:48

While investigating a stack trace discrepancy when composing another answer, I came across a behavior I do not understand. Consider the following test program (this is as far do

相关标签:
1条回答
  • 2021-02-20 11:11

    You're looking at the effects of a bridge method!

    The test method declared in TestInterface has erasure test(Object), but the test method declared in Test has erasure test(Test). A method lookup for the test(Object) method won't find the test(Test) method, so Java actually puts separate test(Object) and test(Test) methods in Test's bytecode.

    Your first trial uses the test(Test) method, which behaves as you expected. Your other trials use the test(Object) method, which is a synthetic bridge method that just calls the test(Test) method. This bridge method doesn't really have a line number, so it shows up in the stack trace with the fairly arbitrary line number of 11.

    0 讨论(0)
提交回复
热议问题