<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    一葉笑天
    雄關(guān)漫道真如鐵, 而今邁步從頭越。 從頭越, 蒼山如海, 殘陽(yáng)如血。
    posts - 73,comments - 7,trackbacks - 0
    java.lang.Object提供toString方法。一般它包含類(lèi)型+@+無(wú)符號(hào)的十六進(jìn)制的hashcode值。例如“PhoneNumber@163b91.”
    提供一個(gè)toString方法將會(huì)使類(lèi)更便于使用。toString方法將會(huì)在println,printf,assert調(diào)用的時(shí)候自動(dòng)調(diào)用。如果提供一個(gè)好的toString方法給PhoneNumber,可以很容易的提供診斷消息:
    System.out.println("Failed to connect: " + phoneNumber);
    在實(shí)踐中,toString方法應(yīng)該返回對(duì)象包含的所有感興趣信息。
    在實(shí)現(xiàn)toString方法的時(shí)候需要決定是否需要指定返回值的格式。在值對(duì)象類(lèi)中,是需要指定的。
    指定格式的好處是它將對(duì)象變成一個(gè)標(biāo)準(zhǔn)的,清楚的,可讀的對(duì)象。缺點(diǎn)是toString將會(huì)返回你指定的格式。而你將不能修改它。
    是否需要指定格式,需要清楚的文檔化你的意圖。例如:
     1/**
     2* Returns the string representation of this phone number.
     3* The string consists of fourteen characters whose format
     4* is "(XXX) YYY-ZZZZ", where XXX is the area code, YYY is
     5* the prefix, and ZZZZ is the line number. (Each of the
     6* capital letters represents a single decimal digit.)
     7*
     8* If any of the three parts of this phone number is too small
     9* to fill up its field, the field is padded with leading zeros.
    10* For example, if the value of the line number is 123, the last
    11* four characters of the string representation will be "0123".
    12*
    13* Note that there is a single space separating the closing
    14* parenthesis after the area code from the first digit of the
    15* prefix.
    16*/

    17@Override public String toString() {
    18return String.format("(%03d) %03d-%04d",
    19areaCode, prefix, lineNumber);
    20}
    如果你不打算指定格式,文檔結(jié)構(gòu)應(yīng)該像這樣:
    1/**
    2* Returns a brief description of this potion. The exact details
    3* of the representation are unspecified and subject to change,
    4* but the following may be regarded as typical:
    5*
    6* "[Potion #9: type=love, smell=turpentine, look=india ink]"
    7*/

    8@Override public String toString()  }
    在閱讀了上面的文檔后,編寫(xiě)代碼的或者依賴(lài)詳細(xì)格式維護(hù)數(shù)據(jù)的程序員將會(huì)在格式變化時(shí)開(kāi)始抱怨。
    不管你是否指定格式,需要toString來(lái)返回包含信息的值。
    posted on 2008-07-01 21:31 一葉笑天 閱讀(241) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): JAVA技術(shù)
    主站蜘蛛池模板: 亚洲精品夜夜夜妓女网| 久久亚洲AV无码西西人体| 女同免费毛片在线播放| 亚洲丁香婷婷综合久久| 亚洲精品白色在线发布| 亚洲色精品88色婷婷七月丁香 | 日韩免费三级电影| 国产亚洲综合久久| 精品国产亚洲一区二区三区| 日本视频免费在线| 成年网站免费视频A在线双飞| 国产一精品一AV一免费| 一个人看的免费视频www在线高清动漫| 国产亚洲精品xxx| 国产亚洲精品国产福利在线观看| 亚洲精品不卡视频| 亚洲丁香色婷婷综合欲色啪| 久久久久亚洲精品天堂久久久久久| 麻豆国产入口在线观看免费| 18勿入网站免费永久| 久9久9精品免费观看| 99久久成人国产精品免费| 日韩电影免费在线观看网址| 亚洲成熟丰满熟妇高潮XXXXX | 日本妇人成熟免费中文字幕| 欧洲精品码一区二区三区免费看| 亚洲人成人网站18禁| 亚洲色婷婷综合久久| 亚洲人成无码网站久久99热国产| 真人做人试看60分钟免费视频| 美女内射无套日韩免费播放| 精品国产一区二区三区免费| 免费a级毛片无码a∨免费软件 | 日韩一卡2卡3卡4卡新区亚洲| 国产人妖ts在线观看免费视频| 亚欧免费无码aⅴ在线观看| 久久国产精品2020免费m3u8| 国产亚洲高清在线精品不卡| MM1313亚洲国产精品| 噜噜噜亚洲色成人网站| 边摸边吃奶边做爽免费视频99|