• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            woaidongmao

            文章均收錄自他人博客,但不喜標(biāo)題前加-[轉(zhuǎn)貼],因其丑陋,見諒!~
            隨筆 - 1469, 文章 - 0, 評論 - 661, 引用 - 0
            數(shù)據(jù)加載中……

            Object中的toString 方法

             

             

            Object 類 是所有類的根基  默認(rèn)情況下所有的類都會(huì)繼承它

            Object類中存在一個(gè) toString 方法  這個(gè)方法 是隱含的 我們經(jīng)常用到但是沒有注意過

            eg:

            public class Test{

            public static void main(String args[]){

            int a=100;

            int b=200;

            int c;

            c=a+b;

            System.out.println("a+b= "+c);

            }

            }

            上面這個(gè)簡單的例子中就將我們的c 這樣一個(gè)整形轉(zhuǎn)化成一個(gè)字符串進(jìn)行輸出 這樣使用的就是默認(rèn)的toString 方法  使用的是根基類的繼承方法

            但是我們?nèi)绻胍ゴ蛴∫粋€(gè)引用類型的話 可能就達(dá)不到預(yù)期的效果 看一個(gè)例子

            public class Test{

            public static void main(String args[]){

            Dog d=new Dog();

            System.out.println("d:=" +d);

            }

            }

            class Dog{

            }

            這樣去實(shí)現(xiàn)就會(huì)打印出一個(gè)hashcode 也就是在內(nèi)存中的位置   怎么辦?

            必須重寫 toString 方法

            修改一下

            public class Test{

            public static void main(String args[]){

            Dog d=new Dog();

            System.out.println("d:=" +d);

            }

            }

            class Dog{

            public String toString(){

            return "is a hot dog";

            }

            }

            重寫toString 方法 這樣就能夠正常的打印出 is a hot dog

            在我們需要輸出 引用類型的時(shí)候可能需要經(jīng)常的使用toString 方法

             

            //---- 附錄, Object的方法

            protected  Object
            clone()
                      Creates and returns a copy of this object.

            boolean
            equals(Object obj)
                      Indicates whether some other object is "equal to" this one.

            protected  void
            finalize()
                      Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

            Class<?>
            getClass()
                      Returns the runtime class of this Object.

            int
            hashCode()
                      Returns a hash code value for the object.

            void
            notify()
                      Wakes up a single thread that is waiting on this object's monitor.

            void
            notifyAll()
                      Wakes up all threads that are waiting on this object's monitor.

            String
            toString()
                      Returns a string representation of the object.

            void
            wait()
                      Causes the current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object.

            void
            wait(long timeout)
                      Causes the current thread to wait until either another thread invokes the notify() method or the notifyAll() method for this object, or a specified amount of time has elapsed.

            void
            wait(long timeout, int nanos)
                      Causes the current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.

            posted on 2009-06-17 10:04 肥仔 閱讀(547) 評論(0)  編輯 收藏 引用 所屬分類: Web-后臺

            色婷婷综合久久久久中文字幕| 久久久久高潮毛片免费全部播放| 99久久精品国产一区二区蜜芽| 国产福利电影一区二区三区久久久久成人精品综合 | 青青草原综合久久大伊人| 久久久亚洲AV波多野结衣| 久久丫精品国产亚洲av不卡 | 久久久久这里只有精品| 伊人久久无码精品中文字幕| 久久精品国产亚洲av影院| 久久国产三级无码一区二区| 中文字幕乱码久久午夜| 久久99热狠狠色精品一区| 天天做夜夜做久久做狠狠| 国产国产成人精品久久| 国内精品伊人久久久影院| 办公室久久精品| 久久精品夜夜夜夜夜久久| 中文成人无码精品久久久不卡 | 久久天天躁狠狠躁夜夜2020 | 日韩十八禁一区二区久久| 久久久久亚洲AV无码专区体验| 99久久国产亚洲高清观看2024| 99久久国产宗和精品1上映 | 午夜精品久久久久久影视riav| 欧美一区二区三区久久综| 中文字幕无码久久久| 久久精品国产亚洲7777| 欧美伊香蕉久久综合类网站| 亚洲精品无码久久久久sm| 一本色综合久久| 久久久国产视频| 精品久久久久久久久免费影院| 久久九九久精品国产| 国产精久久一区二区三区| 国产精品久久精品| 99久久婷婷国产综合亚洲| 久久青青草原精品影院| 97精品国产91久久久久久| 国产精品岛国久久久久| 伊人丁香狠狠色综合久久|