by Thomas Hawtin <usenet@[EMAIL PROTECTED]
>
Aug 22, 2006 at 05:09 PM
Toby Kim wrote:
> While I'm writing codes on call graph construction of Java programs,
> I've got a question.
> I'm wondering how the class name in the argument of invokevirtual is
> determined.
> Is it the name of a class containing the method definition?
>
> The code snippet (1) is compiled into the bytecode (2).
> Neither printStackTrace() nor equals() are not defined in the
> AWTException.
> But the class name of the first invokevirtual is AWTException,
> whereas the class name of the second invokevirtual is Object. Why is
> that?
The parameter and return types must always match. Working out which
overloaded method to use is done at compile time. In 1.5+, the compiler
synthesises bridge methods for covariant return types.
Which class the method is declared on is not important. Indeed binary
compatibility requires that a method may be moved to a super class.
For methods declared in interfaces, it is preferable to use a class type
if possible because dispatch on a class type is often faster than on an
interface type.
Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/