📄 chap19.html
字号:
<P> </P>
<P>// Method void anotherFinalInstanceMethod()</P>
<P> 0 return</P>
<P> </P>
<P>// Method void exampleInstanceMethod()</P>
<P> 0 aload_0</P>
<P> 1 invokevirtual #9 <Method void instanceMethod() of class Subclass</FONT></P>
<P> 4 aload_0</P>
<P> 5 invokespecial #8 <Method void instanceMethod() of class</P>
<P> ItsABirdItsAPlaneItsSuperclass</FONT></P>
<P> 8 aload_0</P>
<P> 9 invokespecial #11 <Method void privateMethod() of class Subclass</FONT></P>
<P>12 aload_0</P>
<P>13 invokevirtual #7 <Method void finalInstanceMethod() of class</P>
<P> ItsABirdItsAPlaneItsSuperclass</FONT></P>
<P>16 aload_0</P>
<P>17 invokevirtual #5 <Method void anotherFinalInstanceMethod() of</P>
<P> class Subclass</FONT></P>
<P>20 aload_0</P>
<P>21 invokevirtual #10 <Method void interfaceMethod() of class</P>
<P> ItsABirdItsAPlaneItsSuperclass</FONT></P>
<P>24 invokestatic #6 <Method void classMethod() of class</P>
<P> ItsABirdItsAPlaneItsSuperclass</FONT></P>
<P>27 return</P>
<P> </P>
<P>// ------------------------------------</P>
<P>// Methods of class UnrelatedClass</P>
<P> </P>
<P>// Method <init</FONT>()</P>
<P> 0 aload_0</P>
<P> 1 invokespecial #7 <Method java.lang.Object()</FONT></P>
<P> 4 return</P>
<P> </P>
<P>// Method void main(java.lang.String[])</P>
<P> 0 new #3 <Class Subclass</FONT></P>
<P> 3 dup</P>
<P> 4 invokespecial #6 <Method <init</FONT>() of class Subclass</FONT></P>
<P> 7 astore_1</P>
<P> 8 invokestatic #8 <Method void classMethod() of class</P>
<P> ItsABirdItsAPlaneItsSuperclass</FONT></P>
<P>11 invokestatic #8 <Method void classMethod() of class</P>
<P> ItsABirdItsAPlaneItsSuperclass</FONT></P>
<P>14 aload_1</P>
<P>15 invokevirtual #10 <Method void instanceMethod() of class Subclass</FONT></P>
<P>18 aload_1</P>
<P>19 invokevirtual #9 <Method void finalInstanceMethod() of class</P>
<P> ItsABirdItsAPlaneItsSuperclass</FONT></P>
<P>22 aload_1</P>
<P>23 invokevirtual #12 <Method void interfaceMethod() of class</P>
<P> ItsABirdItsAPlaneItsSuperclass</FONT></P>
<P>26 aload_1</P>
<P>27 astore_2</P>
<P>28 aload_2</P>
<P>29 invokeinterface (args 1) #11 <Method void interfaceMethod() of</P>
<P> interface InYourFace</FONT></P>
<P>34 return</P>
</FONT><FONT SIZE="2"><P> </P></FONT><FONT FACE="Courier New">end</FONT></P></PRE>
<H3><EM><P>Returning from Methods</P>
</EM></H3><P>There are several opcodes that return from a method, one for each type of return value. These opcodes, which are shown in Table 19-3, take no operands. If there is a return value, it must be on the operand stack. The return value is popped off the operand stack and pushed onto the operand stack of the calling method's stack frame. The current stack frame is popped, and the calling method's stack frame becomes current. The program counter is reset to the instruction in the calling method just following the instruction that invoked the returning method.</P>
<P>Table 19-3. Returning from methods</P>
<TABLE WIDTH="500">
<TR><TD VALIGN="TOP"><STRONG>Opcode</STRONG></TD><TD VALIGN="TOP"><STRONG>Operand(s)</STRONG></TD><TD VALIGN="TOP"><STRONG>Description</STRONG></TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">ireturn</FONT></TD><TD VALIGN="TOP">none</TD><TD VALIGN="TOP">pop <FONT FACE="Courier New">int</FONT>, push onto stack of calling method and return</TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">lreturn</FONT></TD><TD VALIGN="TOP">none</TD><TD VALIGN="TOP">pop <FONT FACE="Courier New">long</FONT>, push onto stack of calling method and return</TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">freturn</FONT></TD><TD VALIGN="TOP">none</TD><TD VALIGN="TOP">pop <FONT FACE="Courier New">float</FONT>, push onto stack of calling method and return</TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">dreturn</FONT></TD><TD VALIGN="TOP">none</TD><TD VALIGN="TOP">pop <FONT FACE="Courier New">double</FONT>, push onto stack of calling method and return</TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">areturn</FONT></TD><TD VALIGN="TOP">none</TD><TD VALIGN="TOP">pop object reference, push onto stack of calling method and return</TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">return</FONT></TD><TD VALIGN="TOP">none</TD><TD VALIGN="TOP">return void</TD></TR>
</TABLE>
<P>The <FONT FACE="Courier New">ireturn</FONT> instruction is used for methods that return <CODE>int</CODE>, <CODE>char</CODE>, <CODE>byte</CODE>, or <CODE>short</CODE>.</P>
<H3><EM><P>On the CD-ROM</P>
</EM></H3><P>The CD-ROM contains the source code examples from this chapter in subdirectories of the <FONT FACE="Courier New">invoke</FONT> directory.</P>
<H3><EM><P>The Resources Page</P>
</EM></H3><P>For more information about the material presented in this chapter, visit the resources page: <FONT FACE="Courier New"><A HREF="http://www.artima.com/insidejvm/invoke.html" tppabs="http://www.artima.com/insidejvm/invoke.html">http://www.artima.com/insidejvm/invoke.html</A></FONT>.</P>
<TABLE BORDER="0" WIDTH="100%">
<TR><TD><A HREF="http://www.pbg.mcgraw-hill.com/betabooks/stores.html" tppabs="http://www.pbg.mcgraw-hill.com/betabooks/stores.html" target="bottom"><IMG SRC="hotkey.gif" tppabs="http://www.pbg.mcgraw-hill.com/betabooks/images/hotkey.gif" ALIGN="LEFT" BORDER="0" WIDTH="40" HEIGHT="40" ALT="Orders"></A>
<IMG SRC="order_text.gif" tppabs="http://www.pbg.mcgraw-hill.com/betabooks/images/order_text.gif" WIDTH="103" HEIGHT="41" ALT="Orders"></TD>
<TD ALIGN="RIGHT"><A HREF="chap18.html" tppabs="http://www.pbg.mcgraw-hill.com/betabooks/venners/chap18.html"><IMG SRC="backward.gif" tppabs="http://www.pbg.mcgraw-hill.com/betabooks/images/backward.gif" BORDER="0" ALT="Backward" WIDTH="32" HEIGHT="32"></A> <A HREF="chap20.html" tppabs="http://www.pbg.mcgraw-hill.com/betabooks/venners/chap20.html"><IMG SRC="forward.gif" tppabs="http://www.pbg.mcgraw-hill.com/betabooks/images/forward.gif" BORDER="0" ALT="Forward" WIDTH="32" HEIGHT="32"></A></TD></TR>
<TR><TD COLSPAN="2"><A HREF="mailto:computing@mcgraw-hill.com"><IMG SRC="hotkey.gif" tppabs="http://www.pbg.mcgraw-hill.com/betabooks/images/hotkey.gif" ALIGN="LEFT" BORDER="0" WIDTH="40" HEIGHT="40" ALT="Comments"></A>
<IMG SRC="comment_text.gif" tppabs="http://www.pbg.mcgraw-hill.com/betabooks/images/comment_text.gif" WIDTH="73" HEIGHT="39" ALT="Comments"></TD></TR>
</TABLE>
<HR>
<P ALIGN=CENTER> <A HREF="http://www.pbg.mcgraw-hill.com/computing/computing-home.html" tppabs="http://www.pbg.mcgraw-hill.com/computing/computing-home.html" TARGET="_top">COMPUTING
MCGRAW-HILL</A> | <A HREF="http://www.pbg.mcgraw-hill.com/betabooks/betabooks-home.html" tppabs="http://www.pbg.mcgraw-hill.com/betabooks/betabooks-home.html" TARGET="_top">Beta Books</A>
| <A HREF="http://www.pbg.mcgraw-hill.com/computing/contact.html" tppabs="http://www.pbg.mcgraw-hill.com/computing/contact.html" TARGET="_top">Contact Us</A>
| <A HREF="http://www.pbg.mcgraw-hill.com/betabooks/stores.html" tppabs="http://www.pbg.mcgraw-hill.com/betabooks/stores.html" TARGET="_top">Order Information</A>
| <A HREF="http://mcgraw-hill.inforonics.com/compsearch.shtml" tppabs="http://mcgraw-hill.inforonics.com/compsearch.shtml" TARGET="_top">Online Catalog</A></P>
<P ALIGN=CENTER><FONT SIZE="-1"><A HREF="http://www.pbg.mcgraw-hill.com/computing/computing-home.html" tppabs="http://www.pbg.mcgraw-hill.com/computing/computing-home.html" TARGET="_top">Computing McGraw-Hill</A> is an imprint of the <A HREF="http://www.pbg.mcgraw-hill.com/pbg-home.html" tppabs="http://www.pbg.mcgraw-hill.com/pbg-home.html" TARGET="_top">McGraw-Hill Professional Book Group</A>.</FONT></P>
<!-- begin footer -->
<HR>
<A HREF="http://www.mcgraw-hill.com/" tppabs="http://www.mcgraw-hill.com/" TARGET="_top"><IMG SRC="division-white.gif" tppabs="http://www.pbg.mcgraw-hill.com/images/division-white.gif" WIDTH="350" HEIGHT="44" ALT="A Division of the McGraw-Hill Companies" BORDER="0"></A><BR>
<FONT SIZE="-2">Copyright © 1997 <A HREF="http://www.mcgraw-hill.com/" tppabs="http://www.mcgraw-hill.com/" TARGET="_top">
The McGraw-Hill Companies</A>. All rights reserved. Any use is subject to the
<A HREF="http://www.mcgraw-hill.com/corporate/news_info/copyrttm.htm" tppabs="http://www.mcgraw-hill.com/corporate/news_info/copyrttm.htm" TARGET="_top">
Terms of Use</A>; the corporation also has a comprehensive <A HREF="http://www.mcgraw-hill.com/corporate/news_info/privacy.html" tppabs="http://www.mcgraw-hill.com/corporate/news_info/privacy.html" TARGET="_top">
Privacy Policy</A> governing information we may collect from our customers.</FONT>
<!-- end footer -->
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -