亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? appenda.htm

?? Thinking in Java, 2nd edition
?? HTM
?? 第 1 頁 / 共 5 頁
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<!--
This document was converted from RTF source: 
By rtftohtml 4.19
See http://www.sunpack.com/RTF
Filename:TIJ2.rtf
Application Directory:C:\TOOLS\RTF2HTML\
Subject:
Author:Bruce Eckel
Operator:Bruce Eckel
Document Comments:
Version Comments:
Comments:
Keywords:
Translation Date:05/21/2001
Translation Time:10:39:33
Translation Platform:Win32
Number of Output files:23
This File:AppendA.htm
SplitDepth=1
SkipNavPanel=1
SkipLeadingToc=1
SkipTrailingToc=1
GenContents=1
GenFrames=1
GenIndex=1
-->
<HEAD lang="en"><META http-equiv="Content-Type" content="text/html">
<TITLE>A: Passing &amp; Returning Objects</TITLE>
</HEAD>

<BODY  BGCOLOR="#FFFFFF"><DIV ALIGN="CENTER">
  <a href="http://www.MindView.net">
  <img src="mindview.gif" alt="MindView Inc." BORDER = "0"></a>
  <CENTER>
    <FONT FACE="Verdana" size = "-1">
    [ <a href="README.txt">Viewing Hints</a> ]
    [ <a href="RevHist.htm">Revision History</a> ]
    [ <a href="http://www.mindview.net/Books/TIJ/">Book Home Page</a> ]
    [ <a href="http://www.mindview.net/Etc/MailingList.html">Free Newsletter</a> ] <br>
    [ <a href="http://www.mindview.net/Seminars">Seminars</a> ]
    [ <a href="http://www.mindview.net/CDs">Seminars on CD ROM</a> ]
    [ <a href="http://www.mindview.net/Services">Consulting</a> ]
    </FONT>
  <H2><FONT FACE="Verdana">
  Thinking in Java, 2nd edition, Revision 12</FONT></H2>
  <H3><FONT FACE="Verdana">&copy;2000 by Bruce Eckel</FONT></H3>
  
    <FONT FACE="Verdana" size = "-1">
     [ <a href="Chap15.htm">Previous Chapter</a> ] 
    [ <a href="SimpCont.htm">Short TOC</a> ] 
    [ <a href="Contents.htm">Table of Contents</a> ] 
    [ <a href="DocIdx.htm">Index</a> ]
     [ <a href="AppendB.htm">Next Chapter</a> ] 
    </FONT>
    
  </CENTER>
  </P></DIV><A NAME="Appendix_A"></A><A NAME="_Toc375545505"></A><A NAME="_Toc375545421"></A><A NAME="_Toc477690736"></A><A NAME="_Toc481064923"></A><A NAME="Heading599"></A><FONT FACE = "Verdana"><H1 ALIGN="LEFT">
A: Passing &amp; Returning Objects</H1></FONT>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia" SIZE=4><backtalk:display ID=TIJ3_APPENDIXA_I0>
By now
you should be reasonably comfortable with the idea that when you&#8217;re
&#8220;passing&#8221; an object, you&#8217;re actually passing a
reference.</FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">In many programming languages you can use
that language&#8217;s &#8220;regular&#8221; way to pass objects around, and most
of the time everything works fine. But it always seems that there comes a point
at which you must do something irregular and suddenly things get a bit more
complicated (or in the case of C++, quite complicated). Java is no exception,
and it&#8217;s important that you understand exactly what&#8217;s happening as
you pass objects around and manipulate them. This appendix will provide that
insight. 
</backtalk:display>
[&nbsp;<a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_APPENDIXA_I0' 
  target="_blank">Add&nbsp;Comment</a>&nbsp;]

<backtalk:display ID=TIJ3_APPENDIXA_I1>
</FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">Another way to pose the question of this
appendix, if you&#8217;re coming from a programming language so equipped, is
&#8220;Does <A NAME="Index2214"></A><A NAME="Index2215"></A>Java have
pointers?&#8221; Some have claimed that pointers are hard and dangerous and
therefore bad, and since Java is all goodness and light and will lift your
earthly programming burdens, it cannot possibly contain such things. However,
it&#8217;s more accurate to say that Java has pointers; indeed, every object
identifier in Java (except for primitives) is one of these pointers, but their
use is restricted and guarded not only by the compiler but by the run-time
system. Or to put it another way, Java has pointers, but no pointer arithmetic.
These are what I&#8217;ve been calling &#8220;references,&#8221; and you can
think of them as &#8220;safety pointers,&#8221; not unlike the safety scissors
of elementary school&#8212;they aren&#8217;t sharp, so you cannot hurt yourself
without great effort, but they can sometimes be slow and tedious.

</backtalk:display>
[&nbsp;<a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_APPENDIXA_I1' 
  target="_blank">Add&nbsp;Comment</a>&nbsp;]

<backtalk:display ID=TIJ3_APPENDIXA_I2>
</FONT><A NAME="_Toc375545422"></A><A NAME="_Toc481064924"></A><BR></P></DIV>
<A NAME="Heading600"></A><FONT FACE = "Verdana"><H2 ALIGN="LEFT">
Passing references around</H2></FONT>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">When you pass a
<A NAME="Index2216"></A><A NAME="Index2217"></A><A NAME="Index2218"></A>reference
into a method, you&#8217;re still pointing to the same object. A simple
experiment demonstrates this:</FONT><BR></P></DIV>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE><font color=#009900>//: appendixa:PassReferences.java</font>
<font color=#009900>// Passing references around.</font>

<font color=#0000ff>public</font> <font color=#0000ff>class</font> PassReferences {
  <font color=#0000ff>static</font> <font color=#0000ff>void</font> f(PassReferences h) {
    System.out.println(<font color=#004488>"h inside f(): "</font> + h);
  }
  <font color=#0000ff>public</font> <font color=#0000ff>static</font> <font color=#0000ff>void</font> main(String[] args) {
    PassReferences p = <font color=#0000ff>new</font> PassReferences();
    System.out.println(<font color=#004488>"p inside main(): "</font> + p);
    f(p);
  }
} <font color=#009900>///:~</font></PRE></FONT></BLOCKQUOTE>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">The method <B>toString(&#160;)</B> is
automatically invoked in the print statements, and <B>PassReferences</B>
inherits directly from <B>Object</B> with no redefinition of
<B>toString(&#160;)</B>. Thus, <B>Object</B>&#8217;s version of
<B>toString(&#160;) </B>is used, which prints out the class of the object
followed by the address where that object is located (not the reference, but the
actual object storage). The output looks like this:</FONT><BR></P></DIV>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE>p inside main(): PassReferences@1653748
h inside f(): PassReferences@1653748</PRE></FONT></BLOCKQUOTE>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">You can see that both <B>p</B> and
<B>h</B> refer to the same object. This is far more efficient than duplicating a
new <B>PassReferences</B> object just so that you can send an argument to a
method. But it brings up an important issue.

</backtalk:display>
[&nbsp;<a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_APPENDIXA_I2' 
  target="_blank">Add&nbsp;Comment</a>&nbsp;]

<backtalk:display ID=TIJ3_APPENDIXA_I3>
</FONT><A NAME="_Toc375545423"></A><A NAME="_Toc481064925"></A><BR></P></DIV>
<A NAME="Heading601"></A><FONT FACE = "Verdana"><H3 ALIGN="LEFT">
Aliasing<BR><A NAME="Index2219"></A><A NAME="Index2220"></A></H3></FONT>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">Aliasing means that more than one
reference is tied to the same object, as in the above example. The problem with
aliasing occurs when someone <I>writes</I> to that object. If the owners of the
other references aren&#8217;t expecting that object to change, they&#8217;ll be
surprised. This can be demonstrated with a simple example:</FONT><BR></P></DIV>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE><font color=#009900>//: appendixa:Alias1.java</font>
<font color=#009900>// Aliasing two references to one object.</font>

<font color=#0000ff>public</font> <font color=#0000ff>class</font> Alias1 {
  <font color=#0000ff>int</font> i;
  Alias1(<font color=#0000ff>int</font> ii) { i = ii; }
  <font color=#0000ff>public</font> <font color=#0000ff>static</font> <font color=#0000ff>void</font> main(String[] args) {
    Alias1 x = <font color=#0000ff>new</font> Alias1(7);
    Alias1 y = x; <font color=#009900>// Assign the reference</font>
    System.out.println(<font color=#004488>"x: "</font> + x.i);
    System.out.println(<font color=#004488>"y: "</font> + y.i);
    System.out.println(<font color=#004488>"Incrementing x"</font>);
    x.i++;
    System.out.println(<font color=#004488>"x: "</font> + x.i);
    System.out.println(<font color=#004488>"y: "</font> + y.i);
  }
} <font color=#009900>///:~</font></PRE></FONT></BLOCKQUOTE>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">In the line:</FONT><BR></P></DIV>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE>Alias1 y = x; <font color=#009900>// Assign the reference</font></PRE></FONT></BLOCKQUOTE>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">a new <B>Alias1</B> reference is created,
but instead of being assigned to a fresh object created with <B>new</B>,
it&#8217;s assigned to an existing reference. So the contents of reference
<B>x</B>, which is the address of the object <B>x</B> is pointing to, is
assigned to <B>y</B>, and thus both <B>x</B> and <B>y</B> are attached to the
same object. So when <B>x</B>&#8217;s <B>i</B> is incremented in the statement:

</backtalk:display>
[&nbsp;<a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_APPENDIXA_I3' 
  target="_blank">Add&nbsp;Comment</a>&nbsp;]

<backtalk:display ID=TIJ3_APPENDIXA_I4>
</FONT><BR></P></DIV>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE>x.i++;</PRE></FONT></BLOCKQUOTE>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia"><B>y</B>&#8217;s <B>i </B>will be
affected as well. This can be seen in the output:</FONT><BR></P></DIV>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE>x: 7
y: 7
Incrementing x
x: 8
y: 8</PRE></FONT></BLOCKQUOTE>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">One good solution in this case is to
simply not do it: don&#8217;t consciously alias more than one reference to an
object at the same scope. Your code will be much easier to understand and debug.
However, when you&#8217;re passing a reference in as an argument&#8212;which is
the way Java is supposed to work&#8212;you automatically alias because the local
reference that&#8217;s created can modify the &#8220;outside object&#8221; (the
object that was created outside the scope of the method). Here&#8217;s an
example: 
</backtalk:display>
[&nbsp;<a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_APPENDIXA_I4' 
  target="_blank">Add&nbsp;Comment</a>&nbsp;]

<backtalk:display ID=TIJ3_APPENDIXA_I5>
</FONT><BR></P></DIV>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE><font color=#009900>//: appendixa:Alias2.java</font>
<font color=#009900>// Method calls implicitly alias their</font>
<font color=#009900>// arguments.</font>

<font color=#0000ff>public</font> <font color=#0000ff>class</font> Alias2 {
  <font color=#0000ff>int</font> i;
  Alias2(<font color=#0000ff>int</font> ii) { i = ii; }
  <font color=#0000ff>static</font> <font color=#0000ff>void</font> f(Alias2 reference) {
    reference.i++;
  }
  <font color=#0000ff>public</font> <font color=#0000ff>static</font> <font color=#0000ff>void</font> main(String[] args) {
    Alias2 x = <font color=#0000ff>new</font> Alias2(7);
    System.out.println(<font color=#004488>"x: "</font> + x.i);
    System.out.println(<font color=#004488>"Calling f(x)"</font>);
    f(x);
    System.out.println(<font color=#004488>"x: "</font> + x.i);
  }
} <font color=#009900>///:~</font></PRE></FONT></BLOCKQUOTE>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">The output is:</FONT><BR></P></DIV>

<BLOCKQUOTE><FONT SIZE = "+1"><PRE>x: 7
Calling f(x)
x: 8</PRE></FONT></BLOCKQUOTE>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">The method is changing its argument, the
outside object. When this kind of situation arises, you must decide whether it
makes sense, whether the user expects it, and whether it&#8217;s going to cause
problems. 
</backtalk:display>
[&nbsp;<a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_APPENDIXA_I5' 
  target="_blank">Add&nbsp;Comment</a>&nbsp;]

<backtalk:display ID=TIJ3_APPENDIXA_I6>
</FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">In general, you call a method in order to
produce a return value and/or a change of state in the object <I>that the method
is called for</I>. (A method is how you &#8220;send a message&#8221; to that
object.) It&#8217;s much less common to call a method in order to manipulate its
arguments; this is referred to as &#8220;calling a method for its
<A NAME="Index2221"></A><I>side effects</I>.&#8221; Thus, when you create a

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲成va人在线观看| 欧美精品在欧美一区二区少妇| 丰满少妇在线播放bd日韩电影| 91小视频免费观看| 精品久久久久久久人人人人传媒| 亚洲日本va午夜在线影院| 久久久精品免费免费| 亚洲va国产天堂va久久en| 成人小视频在线| 日韩一级黄色片| 亚洲黄色片在线观看| 成人免费毛片片v| 日韩欧美一级精品久久| 一区二区日韩电影| av电影在线观看一区| 国产亚洲污的网站| 蜜桃视频一区二区三区| 在线观看日韩国产| 国产精品久久久久久妇女6080| 久草精品在线观看| 欧美精品v国产精品v日韩精品| 亚洲黄一区二区三区| 不卡的看片网站| 日本在线不卡视频| 色偷偷久久人人79超碰人人澡| 国产欧美精品一区二区色综合| 在线播放亚洲一区| 免费不卡在线视频| 91精品欧美久久久久久动漫 | 中文字幕不卡一区| 狠狠色综合日日| 日韩精品一区二区三区视频播放| 亚洲第一福利视频在线| 欧美老肥妇做.爰bbww视频| 亚洲亚洲人成综合网络| 91视视频在线观看入口直接观看www | 亚洲最大成人综合| 亚洲精品一区二区三区影院| 国产日韩欧美精品综合| 国产精品亚洲专一区二区三区| 精品999在线播放| 久久超级碰视频| 精品99999| 国产精品一色哟哟哟| 亚洲国产精品99久久久久久久久| 国产精品中文字幕欧美| 国产精品久久久爽爽爽麻豆色哟哟| 欧美亚洲愉拍一区二区| 亚洲成精国产精品女| 欧美一区二区在线播放| 国产老肥熟一区二区三区| 国产精品乱码一区二区三区软件| 99精品视频中文字幕| 亚洲妇女屁股眼交7| 日韩一区二区免费在线电影| 国产麻豆成人精品| 亚洲男女毛片无遮挡| 宅男在线国产精品| 国产一区二区精品久久91| 337p粉嫩大胆色噜噜噜噜亚洲| 欧美极品少妇xxxxⅹ高跟鞋| 国产成人av一区二区三区在线| 中文幕一区二区三区久久蜜桃| 色综合久久久久久久久久久| 亚洲成av人片一区二区梦乃| 亚洲精品一区二区三区四区高清| 成人午夜视频福利| 亚洲电影在线播放| 精品国产欧美一区二区| 色偷偷成人一区二区三区91| 美女看a上一区| 中文字幕一区av| 555www色欧美视频| 99九九99九九九视频精品| 免费人成精品欧美精品 | 亚洲国产精品ⅴa在线观看| 一本色道久久综合亚洲91| 偷拍一区二区三区四区| 国产亚洲欧美日韩在线一区| 在线观看网站黄不卡| 久久99久久99精品免视看婷婷| 91偷拍与自偷拍精品| 日本高清视频一区二区| 国产精品激情偷乱一区二区∴| 欧美日韩一级视频| www.亚洲色图.com| 免费看日韩精品| 中文字幕中文乱码欧美一区二区| 欧美日韩精品福利| av高清不卡在线| 国内欧美视频一区二区| 亚洲午夜视频在线观看| 国产精品美女久久久久高潮| 日韩午夜三级在线| 欧美日韩在线免费视频| www.成人在线| 国产伦精品一区二区三区免费迷| 艳妇臀荡乳欲伦亚洲一区| 欧美精品一区二区在线播放| 欧美日韩中文国产| 在线免费一区三区| 97久久人人超碰| 国产高清不卡一区二区| 蜜臀av一区二区在线观看| 日韩在线卡一卡二| 亚洲国产综合在线| 一区二区三区中文字幕在线观看| 国产精品欧美精品| 欧美国产国产综合| 中文字幕成人av| 国产精品天美传媒| 国产精品免费看片| 中文字幕一区二区三区乱码在线| 久久久久久夜精品精品免费| 精品久久久久久久一区二区蜜臀| 精品久久一区二区| 亚洲一区二区美女| 亚洲精品菠萝久久久久久久| 亚洲三级小视频| 亚洲精品成人在线| 丝袜美腿成人在线| 天天综合色天天| 美国一区二区三区在线播放| 看电影不卡的网站| 国产一区三区三区| 国产jizzjizz一区二区| 成人av网站免费观看| a级高清视频欧美日韩| 91丨国产丨九色丨pron| 欧美亚洲综合久久| 日韩午夜激情免费电影| 久久色中文字幕| 国产精品乱人伦中文| 亚洲视频免费在线| 亚洲一区二三区| 亚洲成人一区在线| 蜜臀av一区二区在线免费观看| 国产在线一区观看| 成人午夜电影网站| 欧美在线一区二区三区| 欧美日韩国产综合一区二区三区| 91精品国产综合久久久蜜臀粉嫩 | 国产精品色呦呦| 亚洲一区二区三区三| 日本中文字幕一区二区有限公司| 老司机免费视频一区二区三区| 国产成人午夜99999| 99精品视频在线播放观看| 欧美军同video69gay| 国产精品天天看| 一区二区三区四区在线播放| 久久不见久久见免费视频1| 国产成人精品免费一区二区| 一本久久综合亚洲鲁鲁五月天| 欧美酷刑日本凌虐凌虐| 欧美国产欧美综合| 蜜臀av性久久久久蜜臀aⅴ| 成人黄色小视频| 91精品国产欧美一区二区18| 中文天堂在线一区| 久久精品国产澳门| 色综合久久久久综合99| 久久精品这里都是精品| 亚洲高清中文字幕| 国产精品 日产精品 欧美精品| 欧美三区在线观看| 日本一区二区动态图| 免费在线观看不卡| 欧美体内she精视频| 精品久久久久香蕉网| 图片区小说区国产精品视频| jlzzjlzz亚洲女人18| 日韩一区二区精品葵司在线 | 91一区在线观看| 精品久久免费看| 日韩电影在线一区二区三区| 成人黄色综合网站| 亚洲激情成人在线| 粉嫩aⅴ一区二区三区四区五区| 欧美电影免费观看完整版| 亚洲午夜影视影院在线观看| 国产91精品露脸国语对白| 色婷婷国产精品久久包臀 | 99热精品一区二区| 国产色产综合产在线视频| 日韩成人av影视| 欧美少妇xxx| 亚洲一级在线观看| 91视频免费看| 中文字幕一区二区三区视频| 成人网在线播放| 欧美高清一级片在线观看| 国产麻豆一精品一av一免费| 精品噜噜噜噜久久久久久久久试看| 午夜精品久久久久久不卡8050| 色综合网站在线| 亚洲午夜国产一区99re久久| 91免费版在线| 亚洲免费在线电影| 色综合久久综合网97色综合|