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

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

            Object中的toString 方法

             

             

            Object 類 是所有類的根基  默認情況下所有的類都會繼承它

            Object類中存在一個 toString 方法  這個方法 是隱含的 我們經常用到但是沒有注意過

            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);

            }

            }

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

            但是我們如果想要去打印一個引用類型的話 可能就達不到預期的效果 看一個例子

            public class Test{

            public static void main(String args[]){

            Dog d=new Dog();

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

            }

            }

            class Dog{

            }

            這樣去實現就會打印出一個hashcode 也就是在內存中的位置   怎么辦?

            必須重寫 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

            在我們需要輸出 引用類型的時候可能需要經常的使用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 肥仔 閱讀(550) 評論(0)  編輯 收藏 引用 所屬分類: Web-后臺

            热99RE久久精品这里都是精品免费| 久久久久久午夜精品| 久久人人爽人人爽人人片AV不| 久久精品国产99国产精品导航| 三级片免费观看久久| 午夜视频久久久久一区| 中文国产成人精品久久不卡| 亚洲va中文字幕无码久久| 久久精品国产91久久综合麻豆自制| 99久久精品国产一区二区蜜芽 | 国产精品va久久久久久久| 久久久久久亚洲精品不卡| 久久亚洲AV成人无码国产| 国产日韩久久免费影院| 人妻无码αv中文字幕久久| 国产福利电影一区二区三区久久老子无码午夜伦不 | 狠狠狠色丁香婷婷综合久久俺| 久久99精品免费一区二区| 色综合久久久久久久久五月| 久久se精品一区精品二区国产 | 一本大道加勒比久久综合| 国产亚洲美女精品久久久2020| 久久er热视频在这里精品| 久久综合亚洲色一区二区三区| 亚洲国产精久久久久久久| 无码日韩人妻精品久久蜜桃 | 国内精品伊人久久久久777| 99久久精品免费看国产一区二区三区| 久久婷婷五月综合97色直播| 国产激情久久久久影院小草 | 精品久久久久久亚洲精品| 亚洲午夜无码久久久久| 热久久国产欧美一区二区精品| 久久免费美女视频| 亚洲国产二区三区久久| 国产精品天天影视久久综合网| 亚洲va久久久噜噜噜久久天堂| 久久AV高潮AV无码AV| 久久精品国产久精国产果冻传媒| 亚洲国产成人久久笫一页| 久久受www免费人成_看片中文|