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
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.