$30 off During Our Annual Pro Sale. View Details »

ふつうのJavaコーディング #ccc_e1

irof
May 20, 2017
20k

ふつうのJavaコーディング #ccc_e1

JJUG CCC 2017 Spring E1
2017-05-20 10:00-10:45

irof

May 20, 2017
Tweet

Transcript

  1. ;ͭ͏ͷ
    +BWBίʔσΟϯά
    !JSPG
    DDD@F
    ++6($$$4QSJOH

    View Slide

  2. JSPG
    ؔ੢+BWBΤϯδχΞͷձ
    େࡕࡏॅ
    ;ͭ͏ͷϓϩάϥϚ
    ࡢ೥຤ʹձࣾ΍Ίͯɺ
    ͳΜͱͳ͘ϑϦʔͯ͠·͢ɻ

    View Slide

  3. ࿐෷͍

    View Slide

  4. ͜ͷηογϣϯ͸ʔ
    w ࢲͷݴޠԽͰ͖ͯͳ͍Կ͔ΛͭΒͭΒͱ࿩͠·͢ɻ
    w ීஈͷίʔσΟϯά΍ϨϏϡʔͱশͯ͠ద౰ʹோΊͨ
    Γ೉บ͚ͭͨΓͯ͠Δͱ͖ʹɺؾʹͯ͠Δͱ͜Ζͱ͔
    Λɺ൒͹ڧҾʹݴޠԽ͠Α͏ͱࢼΈͨ΋ͷͰ͢ɻ
    w ਖ਼͍͠ղ͸͋Γ·ͤΜɻͱݴ͏͔ɺ͖ͬͱ͋ͳͨͷί
    ϯςΩετͰ͸ؒҧ͍΋͋Γ·͢ɻڧΊͷݴ༿Λ࢖ͬ
    ͯͨΓ͢Δ͚Ͳɺ͜͜Ͱμϝͱ͔ݴͬͯΔͷΛฏવͱ
    ΍Δ͜ͱ΋͋Γ·͢ɻ

    View Slide

  5. ;ͭ͏ʔ
    w ;ͭ͏ɺී௨ɺීஈ௨Γ
    w ͍ͭ΋΍ͬͯΔ͜ͱ
    w ͻΒ͕ͳʹਂ͍ҙຯ͸ͳ͍Ͱ͢

    View Slide

  6. ίʔυ͹͔Γݟͯ΋͞ʔ
    w ʮίʔυ͚ͩʹͩ͜Θͬͯ΋࢓ํ͕ͳ͍ʯͱ͔ݴ͏͚Ε
    ͲɺຊؾͰਅ݋ʹίʔυʹͩ͜ΘΔͳΒɺશମΛݟ͟Δ
    Λಘͳ͘ͳΔΑ
    w ίʔυʹͩ͜ΘΔͨΊʹ
    w ϓϩμΫτ͸ྑ͍΋ͷͰͳ͚Ε͹ͳΒͳ͍
    w ϓϩδΣΫτ͸ԁ׈ʹ·ΘΒͳ͍ͱ͍͚ͳ͍
    w Ϗδωε͸੒ޭ͠ͳ͖Ό͍͚ͳ͍

    View Slide

  7. ίʔυ͸ಡΈ෺
    ಡΉ ॻ͘
    ʼ
    ճ਺

    View Slide

  8. ίʔυ͸ಡΈ෺
    ಡΉ
    ॻ͘ ʼ
    ର৅ͷৄ͠͞

    View Slide

  9. ίʔυ͸ಡΈ෺
    w ॻ͕͔͔࣌ؒͬͯ͘΋ɺಡΉ͕࣌ؒ୹ॖ͞ΕΔͳΒ
    ͹ɺ࣌ؒΛ͔͚ͯॻ͜͏
    w ৑௕ʹॻ͚ͱݴ͏ҙຯͰ͸ͳ͍
    w ॻ͘ͷʹ΋ಡΉͷʹ΋͕͔͔࣌ؒΔͱ͔࠷ѱ

    View Slide

  10. ਆ͸ࡉ෦ʹ॓Δ
    ѱຐ͸ࡉ෦ʹજΉ
    ίʔυ͕ࡉ෦͔Ͳ͏͔͸஌
    Βͳ͍͚ΕͲɻ

    View Slide

  11. ͍ͩ͡ͳ͜ͱ

    View Slide

  12. w ॻ͍ͨίʔυͷҰߦҰߦɺҰจࣈҰจࣈ
    Λઆ໌Ͱ͖ΔͷͰ͋Ε͹ɺ͖ͬͱͦΕ͸
    ͍͍ίʔυɻ

    View Slide

  13. ͳͥͦ͏ίʔσΟϯά͔ͨ͠Λઆ໌Ͱ
    ͖ΔΑ͏ʹͳΓ·͠ΐ͏ɻઆ໌Ͱ͖Δ
    ίʔυ͸ෆ۩߹΋গͳ͘อक΋͠΍͢
    ͍͸ͣͳͷͰɺ͖ͬͱ͍͍݁Ռʹͭͳ
    ͕Δ͸ͣͰ͢ɻ
    l
    +BWBΤϯδχΞཆ੒ಡຊ+BWBೖ໳ΑΓ
    ʢࣗ෼Ͱॻ͍ͨʣ

    View Slide

  14. ஈҐ
    ࿩ͷͨΊͷ۠੾ΓͳͷͰɺݫີͳ΋ͷͰ͸ͳ͍Ͱ͢ɻೝఆ΋͠·ͤΜɻ

    View Slide

  15. ॳஈ ೖ໳
    ೋஈ ݞ׳Β͠
    ࡾஈ ϝιουΛखջ͚Δ
    ࢛ஈ ҆৺Ͱ͖ΔΦϒδΣΫτ
    ޒஈ දݱྗʹͩ͜ΘΔ
    ࿡ஈ 4USFBNͱͷ෇͖߹͍͔ͨ
    ࣣஈ ܕΛҙࣝ͢Δ
    ീஈ جຊతͳࢦ਑Λ࣋ͭ
    ۝ஈ

    View Slide

  16. ॳஈ

    View Slide

  17. ίʔσΟϯάن໿͕͋Ε͹ɺͱΓ͋͑ͣकΔ
    ίʔσΟϯάن໿͕ΰϛͳ͜ͱ΋͋Δ͠ɺ݁ߏଟ͍
    ͚ΕͲɺ·ͣ͸कΔ
    ن໿ʹ͸ʢࣦΘΕ͍ͯΔ͜ͱ΋ଟ͍Ͱ͕͢ʣཧ༝ͱ
    ܦҢ͕͋Γ·͢ɻͦΕΛઆ໌Ͱ͖ͣʹഁΔͷ͸࣌ظ
    ঘૣͰ͢ɻഁΔͷ͸ɺਖ਼߈๏Ͱਅਖ਼໘͔ΒഁΕΔΑ
    ͏ʹͳ͔ͬͯΒɻ
    ίʔσΟϯάن໿ʹ४ڌ͢Δ

    View Slide

  18. ͦΕͬΆ͍ຊΛͬ͟ͱಡΜͰʮ͏Μ͏Μͦ͏ͩΑ
    Ͷʔʯͱ͔ݴ͏͘Β͍͸͢Δɻ
    ͜ͷ΁Μͷδϟϯϧͳͷ͚ͩΕͲɺͲΕ΋एׯݹ͍
    ͷ͸ಥͬࠐΜͰ༡Ϳͱ͍͍೰·͍͠ͱ͜Ζɻ
    ҰൠతͳϧʔϧΛᅂΉ

    View Slide

  19. ೋஈ

    View Slide



  20. ۭ-JTUͷͨΊʹ"SSBZ-JTUΛ࢖Θͳ͍
    return new ArrayList<>();
    return Collections.emptyList();

    View Slide

  21. if (hoge.isFuga()) {
    //...(a)
    }
    //...ʢ͕͜͜௕͍΄Ͳμϝ͕͞૿͢ʣ
    if (hoge.isFuga()) {
    //...(b)
    }
    टΛ܏͛ͯ͠·͏JG

    B
    Λ௨ͬͯ C
    Λ௨Βͳ͍ͷ͕ύε্ଘࡏ͢Δ

    View Slide

  22. int value = ... // 0 or 1
    if (value == 0) {
    //...(a)
    }
    if (value == 1) {
    //...(b)
    }
    टΛ܏͛ͯ͠·͏JG

    Լ͸WBMVF΍FMTFͱ͸ҧ͏ҙຯͳͷʁ B
    ΋ C
    ΋௨Βͳ͍ͷͬͯ͋Δͷʁ
    ͍͍ͩͨͷ৔߹͸FOVNΛ࢖͏΂͖ɻ
    FOVNΛ࢖͍౗͢

    View Slide

  23. ΞϓϦέʔγϣϯίʔυϨϕϧͰ͸ඞཁͳ͍
    ࢖͍ͨ͘ͳͬͨΒཱͪࢭ·Δ
    ࢖ΘͣʹͳΜͱ͔Ͱ͖ͳ͍͔ߟ͑ͯɺղܾͰ͖ͳ͍
    ͳΒղܾͰ͖Δਓʹ͓ئ͍͢Δ
    Ͳ͏͠Α͏΋ͳ͔ͬͨΒɺޙչ͠ͳ͕Β࢖͏
    ΩϟετΛ࢖Θͳ͍
    ϨΠϠʹԠͨ͡ਫ४ͷ"1*Λ࢖͏

    View Slide

  24. Charset.forName("UTF-8")
    StandardCharset.UTF_8
    list.isEmpty()
    list.size() == 0
    !list.isEmpty()
    list.size() != 0
    list.size() > 0
    ಉ͜͡ͱ͸ಉ͡Α͏ʹॻ͘
    ಉ͡ϝιου಺ʹࠞࡏͯ͠ΔͱͭΒ͍

    View Slide

  25. ࡾஈ

    View Slide



  26. ݻఆ஋ͷҾ਺͸ϝιουΛ࡞Δ
    method(MyEnum.HOGE);
    method(MyEnum.FUGA);
    methodHOGE();
    methodFUGA();
    ࣮ࡍ͜Μͳϝιου໊͚ͭͨΒԥΓ·͕͢ɻ

    View Slide



  27. ϑϥάύϥϝʔλΛආ͚Δ
    void method(boolean flg);
    void trueMethod();
    void falseMethod();

    View Slide

  28. ઌʹ͋͛ͨͷ͸ͭͷࢦ਑ʹΑΔ
    ϝιουʹҾ਺Λ૿΍ͦ͏͔ͱࢥͬͨ৔߹͸ϝιο
    υ௥ՃΛઌʹߟ͑Δ
    Ҿ਺Λ૿΍͢લʹϝιου௥ՃΛߟ͑Δ
    Ҿ਺͸গͳ͘͢Δ
    ໊લͰදݱ͢Δ

    View Slide

  29. ҰͭͷϝιουͰෳ਺ରԠͰ͖ͨํ͕൚༻ੑ͕ߴ͘
    ͍͍ͯ͡Όͳ͍͔ͬͯ࿩΋͋Δ͔΋͠Εͳ͍͚ΕͲɺ
    ಛʹQVCMJDͳͷ͸ಛԽͨ͠ϝιουΛ࡞੒͢Δ
    QSJWBUFϝιουͳΒ࢖ͬͯྑ͍ʢείʔϓ͕ڱ͚Ε
    ͹ಛʹ໰୊ʹͳΒͳ͍ʣ
    ʮΘ͟Θ͟ϝιου࡞Δͷʁʯ
    ίʔυ͸ಡΉํ͕ଟ͍

    View Slide



  30. ৚݅ࣜΑΓϝιουΛ޷Ή
    if (list.size() == 0) { ...
    if (age >= 20) { ...
    if(list.isEmpty()) { ...
    if (isAdult()) { ...

    View Slide



  31. ಉ͡ΦϒδΣΫτΛԿ౓΋ݺ͹ͳ͍
    if (hoge.isFoo()) {
    hoge.bar();
    }
    hoge.barIfFooIsTrue();
    ಉ͜͡ͱΛ͍ͯ͠ΔͳΒಉ͡ʹ͢Δ

    View Slide



  32. BOE΍PS͸ϝιουΛநग़͢Δ
    if (hoge.isFoo() || hoge.isBar()) {
    //...
    }
    if (hoge.isFooOrBar()) {
    //...
    }
    ಉ͡ΦϒδΣΫτͳΒઈର΍Δ΂͖
    ಉ͡ΦϒδΣΫτΛԿ౓΋ݺ͹ͳ͍
    ৚݅ࣜΑΓϝιουΛ޷Ή

    View Slide



  33. ·ͱΊΔͱ
    if (status == Status.SUCCESS
    || status == Status.FAIURE) {
    //...
    }
    if (status.isFinish()) {
    //...
    }
    FOVNΛͨͩͷྻڍͱͯ͠࢖ͬͯΔͱ΍Γ͕ͪͰ͢Ͷ
    FOVNΛ࢖͍౗͢

    View Slide

  34. ͍ͭ΋ಉ͡࢖͍ํΛ͍ͯ͠ΔͷͰ͋Ε͹ɺϝιου
    நग़ͯ͠ɺͦͷմʹ໊લΛ෇͚·͠ΐ͏
    ΍Δ͜ͱ͕ಉ͡ͳͷͰ͋Ε͹ɺຊ౰ʹಉ͡ίʔυΛ
    ࢖͏Α͏ʹ͢Δ
    Ұํɺ݁Ռతʹಉ͡Α͏ͳίʔυʹͳ͍ͬͯΔ͚ͩ
    Ͱ͋Ε͹ɺಉ͡ʹͳΒͳ͍Α͏ʹม͑·͠ΐ͏
    ಉ͜͡ͱΛͯ͠ΔͳΒಉ͡ʹ͢Δ

    View Slide

  35. ϝιου࡞੒Λ
    ໘౗͕͘͞Βͳ͍

    View Slide

  36. ࢛ஈ

    View Slide

  37. class Hoge {
    Foo foo;
    Bar bar;
    Hoge(Foo foo) { this.foo = foo; }
    Hoge(Bar bar) { this.bar = bar; }
    ...
    }
    த్൒୺ͳΫϥεΛ࡞Βͳ͍
    GPP΋͘͠͸CBS͔͠ೖΒͳ͍Ϋϥε

    View Slide

  38. Object obj;
    if (condA()) obj = methodA();
    if (condB()) obj = methodB();
    if (condC()) obj = methodC();
    // ... objΛ࢖ͬͯԿ͔͢Δ
    ࠶୅ೖΛආ͚Δ
    PCKͷঢ়ଶ͕ෆ҆ఆʹͳΔ

    View Slide

  39. class ImmutableObject {
    final Hoge hoge;
    ImmutableObject(Hoge hoge) {
    this.hoge = hoge;
    }
    }
    ΠϛϡʔλϒϧΦϒδΣΫτΛ޷Ή
    ఆٛͰ͸ʮTFUUFSΛ࣋ͨͳ͍ɺϑΟʔϧυ͕pOBMͰQSJWBUFɺΫϥε͕pOBMɺΠϯελϯεϑΟʔϧυ͕Πϛϡʔλϒϧʯ͚ͩͲɺͦ͜·Ͱؾʹ͠ͳ͍ɻ
    ϑΟʔϧυ͕શͯpOBMͳΫϥε

    View Slide

  40. ࠶୅ೖΛආ͚Δͷ΋ɺΠϛϡʔλϒϧΦϒδΣΫτ
    ʹ͢Δͷ΋ɺঢ়ଶભҠΛ࠷খʹ͢ΔͨΊ
    ঢ়ଶભҠ͕͋ΔΦϒδΣΫτΛෳ਺ѻ͏ͱ؆୯ʹࢲ
    ͷཧղΛ௒͑ͯ͠·͏
    ͦΜͳʹͨ͘͞Μͷ͜ͱΛؾʹ͢Δͱ͔ແཧͳͷͰɺ
    ؾʹ͠ͳ͖Ό͍͚ͳ͍͜ͱΛݮΒ੍ͯ͠ޚͰ͖Δঢ়
    ଶΛҡ࣋͢Δ
    ঢ়ଶભҠΛ཈͑Δଞͷࢦ਑΋͋Δ͸ͣɻ๨Εͨɻ
    ঢ়ଶભҠΛ࠷খʹ͢Δ

    View Slide



  41. ίϯετϥΫλ͸νΣΠϯ͢Δ
    Hoge(Object v) { this.v = v; }
    Hoge() {
    this.v = "defaultValue";
    }
    Hoge() {
    this("defaultValue");
    }

    View Slide

  42. w PQFOͨ͠ͷΛͦͷ··ʹ͠ͳ͍
    w Ҿ਺ΛউखʹDMPTF͠ͳ͍
    ϥΠϑαΠΫϧͷରশੑΛอͭ
    PQFOͨ͠ՕॴͰDMPTF͢Δ
    USZXJUISFTPVSDFTΛ
    ࢖͑ΔՕॴΛݟಀ͞ͳ͍

    View Slide

  43. try (ExResource er = hoge::fuga) {
    //...
    }
    -----------------------------------
    class Hoge { void fuga() { ... } }
    interface ExResource
    extends AutoCloseable {
    @Override void close();
    }
    USZXJUISFTPVSDFTΛ࢖͏খٕ
    &YDFQUJPOΛ౤͛ͳ͍DMPTFϝιουΠϯλϑΣʔεʹϝιουϦϑΝϨϯεͰͭͳ͛Δɻ
    Ϋϥεʹ"VUP$MPTFBCMFΛ࣮૷ͤ͞Δͷ΋ݕ౼্ͨ͠Ͱɻ

    View Slide

  44. IUUQJSPGIBUFCMPKQFOUSZQ

    View Slide



  45. ಋग़Ͱ͖Δ஋Λอ࣋͠ͳ͍
    boolean available;
    void setValue(Object value) {
    if (value != null)
    this.available = true;
    }
    boolean isAvailable() {
    return this.value != null;
    }

    View Slide

  46. ҆৺ͯ͠࢖͑Δ
    ΦϒδΣΫτΛ
    खʹ͠Α͏

    View Slide

  47. List list = ...
    // ྫ֎͕ग़Δ͔΋͠Εͳ͍
    list.add(hoge);
    // ྫ֎͕ग़Δ͔΋͠Εͳ͍
    list.remove(hoge);
    ྫ҆৺Ͱ͖ͳ͍ΦϒδΣΫτ

    View Slide

  48. ޒஈ
    ͜ͷล͔Β
    ;Θͬͱͯ͘͠Δ

    View Slide

  49. void method(Object parameter) {
    // ύϥϝʔλ͕null͔΋͠Εͳ͍
    if (parameter == null) {
    return;
    }
    // ...
    }
    ๷ޚతϓϩάϥϛϯάΛආ͚Δ
    ໰୊ͷઌૹΓPSϊΠζ
    OVMMʹ޲͖߹͏

    View Slide

  50. IUUQJSPGIBUFCMPKQFOUSZQ
    l஥ؒ಺Ͱա৒ʹ๷ޚ͠߹͏ɺ୭΋৴͡ΒΕͳ͍ͱͰ΋ݴ͏
    Α͏ͳٙ৺҉َͳίʔυΛॻ͍ͯͲ͏͢ΔΜͩͱ͔ࢥͬͨΓ
    ͠·͢ɻڍಈ͕Α͘Θ͔Βͳ͍֎෦ͷ΋ͷΛ࢖͏ͳΒཧղग़
    དྷ·͕͢ɺࣗ෼੍͕ͨͪޚͰ͖ΔൣғͳΒ͹༨ܭͳ๷ޚͰ
    ίʔυͷՄಡੑΛམͱ͢΂͖͡Όͳ͍ɻͩͬͯͦΕͬͯϊΠ
    ζ͡Όͳ͍Ͱ͔͢ɻ

    View Slide

  51. ৺౰ͨΓ͸͋Δͱࢥ͏ʢࢲ΋͜ͳ͍ͩ࢖ͬͨ
    ׽ࣈͰॻ͘ͱʮ΄͛৘ใʯͱ͔ʮ;͕ॲཧʯͱ͔ͦ
    ΕͬΆ͍͚Ͳɺ೔ຊޠ໊͔Βͯ͠໰୊Ͱ͋Δ
    ҙຯͷͳ໊͍લΛආ͚Δ
    .BOBHFS *OGP
    1SPDFTT 4VNNBSZ
    3FTVMU
    %BUB

    View Slide

  52. w ಉ͡΋ͷʹҧ͏໊લΛ͚ͭͳ͍
    w ҧ͏΋ͷʹಉ໊͡લΛ͚ͭͳ͍
    ɾɾɾΛ෇͚ΒΕΔͱ͍͍ΑͶɻ
    ໊෇͚Ͱؾʹ͢Δ͜ͱ
    ಡΜͩ࣌ʹٙ໰Λ๊͔ͳ໊͍લ

    View Slide

  53. ίϝϯτͰؾʹ͢Δ͜ͱ
    ҆қʹίϝϯτΛॻ͔ͳ͍
    ඞཁͳίϝϯτ͸ॻ͘
    ίʔυ΋ίϝϯτ΋ಡΈखʹԿ͔Λ఻͑Δ΋ͷͳͷ͸ಉ͡ɻ
    ίϝϯτͷํ͕දݱྗ͕ߴ͘ɺίʔυͷํ͕ݫີɻ
    ίϝϯτ͚ͩͰಈ࡞͸͠ͳ͍͚ΕͲɺίʔυ͚ͩ͸ಈ࡞͢Δɻ
    ͦͷͨΊɺίʔυͷදݱྗ͕े෼ߴ͚Ε͹ίʔυ͚ͩͰදݱ͢Δͷ͕͍͍ɻ
    ͱ͸͍͑ίʔυͷදݱྗʹͩ͜ΘΓ͗ͯ͢΋ݶ౓͸͋ΔͷͰɺίϝϯτ͸ඞཁɻ
    ݶ౓͸͖ͬͱࢥ͍ͬͯΔΑΓ΋ͣͬͱԕ͘ʹ͋Δͷ͚ͩΕͲɻ
    όϥϯεΛͱΔ

    View Slide

  54. IUUQJSPGIBUFCMPKQFOUSZQ

    View Slide



  55. ΑΓߴϨϕϧͷ"1*Λ࢖༻͢Δ
    @RequestMapping(value = "/hoge",
    method = RequestMethod.GET)
    String hoge() {
    ...
    @GetMapping("/hoge")
    String hoge() {
    ...
    ݻఆ஋ͷҾ਺͸ϝιουΛ࡞Δ

    View Slide

  56. ͋·Γ࢖ͬͯཉ͘͠ͳ͍"1*͸࢖͍೉͍γάω
    νϟɺҟ༷ͳ໊લʹ͢Δ
    ςετ༻ͷઃఆʢϝʔϧΞυϨεͳͲʣ΍ɺ։ൃ࣌
    ʹ࢖͏ελϒͷ໭Γ஋͸ຊ෺ͬΆ͘͠ͳ͍
    ҧ͏৔໘ͰͦΕ͕࢖ΘΕͨ࣌ʹɺ͘͢͝໨ཱͭΑ͏
    ʹ࡞͓ͬͯ͘
    ؒҧ͍͸ؒҧ͍ͱΘ͔ΔΑ͏ʹ͢Δ

    View Slide

  57. දݱྗʹͩ͜ΘΔ

    View Slide

  58. ࿡ஈ

    View Slide

  59. ೃછΈͷͳ͍"1*͸ɺҰ౓͸΍Γա͗ͳ͘Β͍࢖ͬ
    ͯݟ·͠ΐ͏ɻॻ͍ͯɺಡΜͰɺॻ͖௚ͯ͠ɺͲͬ
    ΀Γਁ͔͍ͬͯͩ͘͞ɻ
    ͱΓ͋͑ͣɺ͋ΒΏΔίϨΫγϣϯૢ࡞Λ4USFBN
    "1*Ͱ΍ͬͯΈΔͷ͕͍͍Ͱ͢ɻ
    ద੾ͳ୊ࡐ͕ͳ͍ͷͳΒɺ$PMMFDUPSTͷϝιουΛ
    ্͔Βॱ൪ʹҰ௨Γ৮Δͱ͍͍Ͱ͢ɻEPXOTUSFBN
    ͱ͔΋࢖͑ΔΑ͏ʹͳΕ͹͍͍ͩͨେৎ෉Ͱ͢ɻ
    4USFBN"1*ͷ࿅श

    View Slide



  60. ϝιουϦϑΝϨϯεΛ޷Ή
    stream
    .filter(hoge -> hoge.isFuga())
    ...
    stream
    .filter(Hoge::isHoge)
    ...
    ϥϜμࣜ͸؆୯ʹෳࡶͰಡΊͳ͍΋ͷʹͳΔɻϝιουϦϑΝϨϯεΛ࢖͏΄͏͕͍͍श׳͕ͭ͘ɻ

    View Slide

  61. 4USFBN"1*ͷཚ༻Λආ͚Δ
    DPNJOH
    TPPO

    View Slide

  62. ࣣஈ

    View Slide

  63. class Hoge {
    LocalDate date = LocalDate.MIN;
    LocalDate getDate() {
    return date;
    }
    }
    ಛघͳ஋Λ֎ʹग़͞ͳ͍
    .*/͕֎ʹग़ͯخ͍͜͠ͱ͸ͳ͍
    OVMM͕Α͘࢖ΘΕΔ͚ͲɺOVMM͸ผ్ɻ
    OVMMʹ޲͖߹͏

    View Slide



  64. ΪϦΪϦ·ͰจࣈྻʹཔΒͳ͍
    if (foo.str().equals(bar.str()) {
    ...
    }
    if (foo.hasSameStr(bar)) {
    ...
    }
    ʮ͍࣋ͬͯΔจࣈྻϓϩύςΟͰൺֱ͍ͨ͠ʯίʔυ͕ҰͭͰ΋ग़͖ͯͨΒɺ͜ͷΫϥε͸ͦ͏ݴ͏ൺֱͷ͞ΕํΛ͢Δ΋ͷͳͷͰ͢ɻ
    Ͱ͖Ε͹͜ͷൺֱʹ͸ద੾ͳ໊લΛ༩͍͑ͨͱ͜Ζɻ͜͜Ͱڍ͛ͨΑ͏ͳػցతͳ໊લ͡Όͳ͘Ͷɻ

    View Slide

  65. ϝιουҾ਺ͳͲͰ҆қʹ࢖ΘΕΔจࣈྻ͸ɺΠϯ
    λϑΣʔεͱͯ͠΋ҙຯ͕޿͗͢Δ͠ɺશͯͷจࣈ
    ྻΛॲཧͰ͖ΔΑ͏ʹ࡞ΒΕ͍ͯΔ͔ඍົͩΖ͏͠ɺ
    ͦ΋ͦ΋ʮશͯͷจࣈྻΛॲཧ͢Δඞཁ͕͋Δʯͳ
    Μͯ͜ͱɺͦ͏ͦ͏ͳ͍ɻ
    จࣈྻͷΑ͏ͳܕͰ΍ΓͱΓ͢ΔͷͰ͸ͳ͘ɺϓϩ
    μΫτͷܕͰΪϦΪϦ·Ͱॲཧ͢ΔɻΪϦΪϦͬͯ
    ͷ͸6*ͱ͔ӬଓԽͱ͔ɺ+BWBͷ֎ʹग़Δ௚લɻग़͞
    ͳ͍͍ͯ͘ͳΒ࠷ޙ·Ͱग़͞ͳ͍ɻ
    ΪϦΪϦ·ͰจࣈྻʹཔΒͳ͍

    View Slide

  66. FOVNΛ࢖͍౗͢
    ݸҎ্ͷ஋Λ࣋ͯΔ
    ϝιουΛ࣋ͯΔ
    ΠϯλϑΣʔεΛ࣮૷Ͱ͖Δ

    View Slide

  67. ʮࣅ͍ͯΔʯͱײͨ͡ͳΒɺܕͰറͬͯΈΔ
    ؾ͍͍ͮͯͳ͔ͬͨ੾Γޱ͕ग़ͯ͘ΔՄೳੑ͸ߴ͘
    ͯɺݴ༿͡ΌදݱͰ͖ͳ͔ͬͨڞ௨ੑ͕͋Δͷ͔΋
    ͠Εͳ͍͠ɺશવҧ͏΋ͷ͕ۮવࣅͨܗʹͳ͍ͬͯ
    ͚͔ͨͩ΋͠Εͳ͍
    ײੑΛ৴ͯ͡ίʔυʹͯ͠ΈΔ
    ຊ౰ʹಉͩͬͨ͡ΒܕʹͰ͖Δ͠ɺҰ౓ܕͰറΕΔ
    ͱ͍Ζ͍ΖָʹͳΔ͚Ͳɺͨ·ʹؒҧ͑Δ
    ࣅͨܗͷߏ଄͸ܕͰറΔ

    View Slide

  68. // ͨͿΜ0Λ࢖͍ͨ͘͸ͳ͍
    int i = 0;
    // ͨͿΜۭจࣈʹ͍ͨ͠Θ͚Ͱ͸ͳ͍
    String str = "";
    // ͨͿΜnullΛ࢖͏΂͖͡Όͳ͍
    Hoge hoge = null;
    OVMMʹ޲͖߹͏

    View Slide

  69. OVMM ͸ڻ͘΄Ͳ҆қʹ࢖ΘΕ͍ͯΔ͕ɺ࣮ࡍ͸
    ࢖ΘΕ͍ͯΔҙຯΑΓ΋ͬͱ൚༻తͳ෺ମɻͳͷʹɺ
    ஋Λ໌֬ʹ͢Δ͜ͱ͔Βಀ͛ͨ৔߹ʹແअؾʹબ୒͞
    Εͯ͠·͏஋ɻ
    ໰୊Λى͜͢ίʔυʹ͸݁ߏͳස౓Ͱ OVMMؚ͕
    ·Ε͍ͯΔɻఆٛ͢Δ͜ͱ͔Βಀ͛ͨͷ͔ͩΒɺͦ͏
    ݴ͏ͱ͜Ζʹෆ۩߹͕જΉͷ͸ࢸۃ౰વɻ
    ͜ΕΒ͸໓ଟʹͰͯ͜ͳ͍͸ͣͳͷͰɺ࢖͏ͱ͖͸શ
    ྗͰݴ͍༁ͷίϝϯτΛॻ͍ͯ࢖͏ɻ
    OVMMʹ޲͖߹͏
    ඞཁͳίϝϯτ͸ॻ͘

    View Slide



  70. ۭΠϯελϯεΛ࡞Δલʹཱͪࢭ·Δ
    Hoge hoge = new Hoge();
    hoge.setValue(value);
    ...
    Hoge hoge = new Hoge(value);
    ΠϛϡʔλϒϧΦϒδΣΫτΛ޷Ή

    View Slide

  71. class Hoge {
    final Fuga fuga;
    final Piyo piyo;
    Hoge() {
    this(new Fuga(), new Piyo());
    }
    Hoge(Fuga fuga, Piyo piyo) {
    this.fuga = fuga;
    this.piyo = piyo;
    ...
    ۭΠϯελϯεΛ࡞Δલʹཱͪࢭ·Δ
    ຊ౰ʹσϑΥϧτίϯετϥΫλΛ࢖༻ͨ͠ΠϯελϯεͰ͍͍ͷʁ
    σϑΥϧτίϯετϥΫλͰੜ੒͞ΕΔΠϯελϯε͸׬શʹಈ࡞͢ΔΑ͏ʹ࡞ΒΕͯΔͷʁ
    ୯ͳΔ஋ͷίϯςφʹͳͬͯͳ͍ʁͦͷίʔυಡΈ΍͍͢ʁ

    View Slide

  72. ͦͷΠϯελϯε͕Կऀ͔આ໌Ͱ͖Δ͔ʁ
    ͦͷΠϯελϯε͸ۭͱͯ͠ਖ਼͘͠ৼΔ෣͏͔ʁ
    ౴͑ΒΕͳ͍ͷͰ͋Ε͹ɺԿ͔ؒҧ͍͑ͯΔɻ๷ޚ
    తϓϩάϥϛϯάͤ͟ΔΛಘͳ͍ঢ়ଶʹͳΔͩΖ͏
    ͠ɺ๷ޚతϓϩάϥϛϯά͸ؒҧͬͨ࢖͍ํͷष͍
    Ͱ͢ɻ
    ۭΠϯελϯεΛ࡞Δલʹཱͪࢭ·Δ
    ๷ޚతϓϩάϥϛϯάΛආ͚Δ

    View Slide

  73. ീஈ

    View Slide

  74. ಉ͡ϨΠϠͰ͸ಉ͡ਫ४ͷ"1*Λ࢖༻͢Δ
    ϨΠϠʹԠͨ͡ਫ४ͷ"1*Λ࢖͏
    ରশੑ
    ରশੑ͸அยతͳίʔυ͚ͩͰͳ͘ɺ৭ʑͳ
    Ϩϕϧʹద༻͢Δ΋ͷɻ

    View Slide



  75. ରশੑίʔυͷந৅౓Λἧ͑Δ
    void hoge() {
    add();
    this.count++;
    save();
    }
    void fuga() {
    add();
    countUp();
    save();
    }

    View Slide

  76. ඍົͳίʔυΛॻ͔͟ΔΛಘͳ͍͕࣌͋Δɻ
    ͍ΖΜͳखΛਚͯ͘͠શྗͰճආΛࢼΈΔͷ͸લఏ
    ͚ͩΕͲɺͦΕͰ΋ಧ͔ͳ͍࣌ɻ
    μϝͳ΋ͷΛ໨ཱͨͤΔɻμϝͩͱΘ͔ΔΑ͏ʹɻ
    μϝͳ΋ͷΛ໨ཱͨͤΔ
    ໨ཱͭ͘Β͍μϝͳίʔυΛॻ͘

    View Slide

  77. ۝ஈ

    View Slide

  78. ڧ͍ҙࢥͰ
    ϧʔϧΛഁΔ

    View Slide

  79. Ϩϕϧͷ্͛ํ

    View Slide

  80. ʮΘ͟Θ͟࡞Δʯ
    ͱ޲͖߹͏

    View Slide

  81. ϝιουͷͱ͜ΖͰ΋৮Ε͚ͨΕͲɺΫϥεͰ΋ͳ
    ΜͰ΋ҰॹɻʮΘ͟Θ͟࡞Δʯͱݴ͏ߟ͑Λҙࣝత
    ʹࣺͯΒΕΔΑ͏ʹ܇࿅͢Δɻ
    ࡞੒͢ΔίετͳΜͯࠣࡉͳ΋ͷͰ͢ɻίετ͕ߴ
    ͍ͱײ͡Δͷ͸ɺ͖ͬͱ࡞Γ׳Ε͍ͯͳ͍͔Βɻ
    Ұํɺ਺͕૿͑ΔͱಡΈͮΒ͘ͳΔͷ΋ࣄ࣮ɻ͍ͭ
    ͩͬͯʮίʔυ͸ಡΈ෺ʯΛୈҰʹҙࣝ͢Δ͜ͱɻ
    Θ͟Θ͟࡞Δʁ

    View Slide

  82. ʮؾΛ͚ͭΔʯ
    ͱ޲͖߹͏

    View Slide

  83. ؾΛ͚ͭͯ࢖Θͳ͍ͱ͍͚ͳ͍"1*͸͚ͬ͜͏ଟ͘
    ͯɺ൚༻తͰͳΜͰ΋Ͱ͖Δܥͷ௿Ϩϕϧ"1*͸ͦ
    ͏ݴ͏܏޲ʹ͋Δ͔Β࢓ํ͕ͳ͍
    Ͱ΋ɺͦͷ࢖͍ํΛؒҧ͑ͨ࣌ʹέΞϨεϛεѻ͍
    ͍ͯ͠Δͱ͸Կ΋มΘΒͳ͍
    ʮؾΛ͚ͭΔʯ
    ؾΛ͚ͭΔʹؒҧ͑ͯ΋͍͍

    View Slide

  84. ʮؾΛ͚͍ͭͯΕ͹ى͜Βͳ͔ͬͨෆ۩߹ʯ͸ɺઃ
    ܭෆඋͷष͍Ͱ͢
    ͦͷϨΠϠͰ࢖ΘΕΔ΂͖Ͱͳ͍දݱྗ΍ந৅౓ͷ
    "1*͕͍ࠞͬͯͯ͡ɺޡͬͨ࢖͍ํΛ͞Ε͕ͨނʹ
    ൃੜͨ͠΋ͷͰ͠ΐ͏
    ઃܭෆඋͷष͍
    ؒҧ͑ΔՄೳੑ͕͋Ε͹ɺؒҧ͑Δ

    View Slide

  85. ࢖͍ํΛنఆ͢ΔɻͦͷͨΊʹ൚༻తͳܕΛͦͷ·
    ·࢖͏ͷΛආ͚Δɻ
    ಛԽͨ͠࢖͍ํͷͨΊͷɺಛԽͨ͠ΫϥεͱɺಛԽ
    ͨ͠ϝιουΛ࡞͍ͬͯ͘ɻ
    4USJOHͱ͔Λ࢖ͬͯΔͱɺ͍ͭ·Ͱ΋ʮTVCTUSJOHͬ
    ͯʯͱ͔ɺ௿Ϩϕϧͳ"1*Λ஻Δ͜ͱʹͳΔɻ
    ͦ΋ͦ΋ؒҧ͑ΒΕͳ͍Α͏ʹ

    View Slide

  86. OVMMͱ޲͖߹͏

    View Slide

  87. ʮ/VMM1PJOUFS&YDFQUJPOʹͳ͔ͬͨΒOVMMνΣοΫ
    ΛೖΕͨʯ͸༗ࡑɻ҆қʹOVMMνΣοΫΛೖΕΔͷ
    ͸ͦͷ৔͠ͷ͗͗͢Δɻ
    ͦ΋ͦ΋OVMM͕ͦ͜ʹݟ͑Δ͜ͱ͕͓͔͍͠
    OVMMͷҾྗʹ߅͏ͨΊʹ͢΂ͯͷ͜ͱΛߟ͑ͯɺ࣮
    ફ͢Δɻ0QUJPOBMʁͲ͏ͩΖ͏Ͷɻ
    ͨͱ͑͹ɾɾɾ
    ಛघͳ஋Λ֎ʹग़͞ͳ͍

    View Slide

  88. IUUQJSPGIBUFCMPKQFOUSZ
    0QUJPOBM
    OVMMΑΓΑ΄Ͳྑ͍͕ɺ౴͑Ͱ͸ͳ͍ɻ

    View Slide

  89. ܕͱ޲͖߹͏
    ⾠ܕܯ࡯ͷํ͸͓ؼΓ͍ͩ͘͞

    View Slide

  90. ϓϦϛςΟϒܕ΍+BWBඪ४ϥΠϒϥϦɺ൚༻ϥΠϒ
    ϥϦʹଘࡏ͢Δܕ͸ɺۀ຿Λද͢ʹ͸൚༻త͗͢Δ
    ྫ͑͹จࣈྻ͸4USJOHͰද͞ΕΔͷ͔΋͠Εͳ͍͚
    ΕͲɺࠓʮจࣈྻͱͯ͠ѻ͓͏ͱ͍ͯ͠ΔԿ͔ʯʹ
    4USJOHͷ͢΂ͯͷػೳ͸ཁΒͳ͍͠ɺ΋ͬͱಛԽ͠
    ͨػೳ͕͋ΔΜ͡Όͳ͍͔ɺͱ͔
    ࢲ͸͢΂ͯͷจࣈྻʹରԠ͢ΔॲཧͳΜͯॻ͖ͨ͘
    ͳ͍ʢগͳ͘ͱ΋ͦ͜ʹ͸ʣ
    ޲͖߹͍ํ

    View Slide

  91. ʮཧ૝ͷίʔυʯ
    ʹ޲͖߹͏

    View Slide

  92. IUUQJSPGIBUFCMPKQFOUSZQ
    ࢲ͸ࣗ෼ͷٻΊ͍ͯΔ$MFBO$PEF UIBUXPSLT
    Λڻ͖
    ͷͳ͍ίʔυͱଊ͍͑ͯΔɻͭ·Γʮී௨ͦ͏ॻ͘ΑͶʯ
    ͱݴΘΕΔΑ͏ͳ΋ͷɻ͋Δ΂ͯࣗ͘͠વͱͦ͏ͳ͍ͬͯΔ
    ΋ͷɻ͓ͦΒ͘ग़དྷ্͕Δίʔυ͸ڽͬͨίʔυͱ͸ݴ
    ΘΕͳ͍ɻ

    View Slide

  93. ൚༻ੑ߅͏

    View Slide

  94. ൚༻ੑ͕ߴ͍͸ਖ਼ٛͷΑ͏ʹޠΒΕ͕ͪɻ
    ͚ͩͲɺ൚༻ΛٻΊΔͱ؆୯ʹखଓ͖తʹͳΔɻ
    ੍ޚ༻ͷύϥϝʔλ͕๲େʹͳΓɺෳࡶͳঢ়ଶભҠ
    Λ࣋ͭΑ͏ʹͳΓɺ૊߹ͤരൃʹԡͭ͠Ϳ͞ΕΔɻ
    γεςϜ։ൃʹ͓͍ͯɺ൚༻ੑΑΓγεςϜʹద͠
    ͨಛԽΛҙࣝ͢Δɻա৒ͳ·ͰʹಛԽ͢Δɻอकੑ
    ͕མͪΔʁ൚༻తʹͯͯ͠อकੑΑ͔ͬͨʁ
    ൚༻ੑͷ༠࿭

    View Slide

  95. ಉ͡໛༷ͱ޲͖߹͏

    View Slide

  96. ͋ΒΏΔϨϕϧͷʮಉ͡໛༷ʯʹහײʹͳΔ
    ෳ਺ͷΫϥεͰࣅͨΑ͏ͳίʔυ͕͋ΔͳΒɺͦͷ
    ʮԿ͕ࣅ͍ͯΔͱײ͔ͨ͡ʯʹ޲͖߹͏
    ίʔυ͚ͩ͡Όͳ͘ɺύοέʔδ΍Ϋϥεߏ੒ɺΠ
    ϯελϯεͷϥΠϑαΠΫϧ΍γʔέϯεʹ΋ʮಉ
    ͡໛༷ʯ͸ݟ͑ͯ͘Δ͸ͣ
    ײ֮Λେࣄʹͯ͠΄͍͠
    ಉ͡໛༷

    View Slide

  97. ࠷ޙʹ

    View Slide

  98. ࡾ೔લͷࣗ෼ͷίʔυɺ

    ποίϛͲ͜ΖຬࡌͰࠔΔɻ
    ʢͱ͔਺೥ݴ͍ଓ͚ͯΔʣ

    View Slide