Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Lombokハンズオン Javado #02

Lombokハンズオン Javado #02

Java Doでしょう #02 (10/04,札幌)

Hiroto YAMAKAWA

October 04, 2015
Tweet

More Decks by Hiroto YAMAKAWA

Other Decks in Programming

Transcript

  1. “Project Lombok makes java a spicier language by adding 'handlers'

    that know how to build and compile simple, boilerplate-free, not- quite-java code.” 1SPKFDU-PNCPL  IUUQTHJUIVCDPNS[XJUTFSMPPUMPNCPL Lombok͸Javaʹ’ϋϯυϥ’Λ௥Ճ͢Δ͜ͱͰɺJavaΛؾͷར͍ͨ ݴޠʹ͢ΔΑʂ ϋϯυϥ͸ ɾγϯϓϧͰ ɾϘΠϥʔϓϨʔτʢ͓͖·Γͷॻ͖ํʣΛ·͵͕ΕΔ ɾJavaͬΆ͘ͳ͍ ίʔυʹ͢ΔϏϧυ΍ίϯύΠϧͷํ๏Λ೺Ѳ͍ͯ͠Δ΋ͷͩΑʂ
  2. public  class  Cat  {      private  static  final  Logger

     log  =  LoggerFactory.getLogger(Cat.class);      private  String  name;      private  String  voice;      private  int  age;      public  Cat()  {          this(null,  null,  0);      }    public  Cat(String  name,  String  voice,  int  age)  {          this.name  =  name;          this.voice  =  voice;          this.age  =  age;      }      public  void  setName(String  name)  {          this.name  =  name;    }    public  String  getName()  {        return  name;    }   //  ҎԼུ… ຖճ࡞੒͢Δ ͓͖·Γͷίʔυ ʢϘΠϥʔϓϨʔτʣ *%&Ͱ͋Δఔ౓ੜ੒Ͱ͖Δ΋ͷ΋͋Δ͕ɺ໘౗ͳ͜ͱ΋͋ΔΑ
  3. ͨͱ͑͹ w (FUUFS4FUUFS w FRVBMT IBTIDPEF w σϑΥϧτҾ਺෇͖
 ίϯετϥΫλ w

    5P4USJOH w OVMMDIFDL w #VJMEFSύλʔϯ w -PHHFS w ม਺ఆٛ w *NNVUBCMF0CKFDU w ஗ԆॳظԽ w FUDʜ -PNCPL͸͜͏͍ͬͨ΋ͷΛΞϊςʔγϣϯͰলུɾઃఆ͢ΔΑ
  4. public  class  Cat  {      private  String  name;  

       public  void  setName(String  name)  {          this.name  =  name;      }      public  String  getName()  {          return  name;      }   } import  lombok.Getter;   import  lombok.Setter;   @Getter   @Setter   public  class  Cat  {      //  ΞϊςʔγϣϯΛ͚ͭΔͱgetName(),  setName(String  name)  ͕࣮૷͞ΕΔ      private  String  name;   } -PNCPLΛ࢖͏ͱʜ
  5. !(FUUFS !4FUUFS QVCMJDDMBTT)BOET0O\ QSJWBUFTUBUJDOBM-PHHFSMPH -PHHFS'BDUPSZHFU-PHHFS )BOET0ODMBTT  QSJWBUF4USJOHJOGP QVCMJDTUBUJDWPJENBJO 4USJOH<>BSHT

    \ )BOET0OUBSHFUOFX)BOET0O  UBSHFUTFU*OGP 䧭⸆  MPHJOGP UBSHFUHFU*OGP  ^ ^ ͜ͷଞɺ(FUUFSͷεϨουηʔϑͳ஗ԆॳظԽ(FUUFSͳͲ΋Մೳ
 ʢྫɿ)BOET0Oʣ (FUUFS4FUUFS͕࡞੒͞Εར༻Ͱ͖Δʂ
  6. !(FUUFS !4FUUFS QVCMJDDMBTT)BOET0OB\ QSJWBUFTUBUJDOBM-PHHFSMPH -PHHFS'BDUPSZHFU-PHHFS )BOET0OBDMBTT  !/PO/VMM QSJWBUF4USJOHJOGP QVCMJDTUBUJDWPJENBJO

    4USJOH<>BSHT \ )BOET0OBUBSHFUOFX)BOET0OB  UBSHFUTFU*OGP 䧭⸆  MPHJOGP UBSHFUHFU*OGP  USZ\ UBSHFUTFU*OGP OVMM  ^DBUDI /VMM1PJOUFS&YDFQUJPOF \ MPHJOGP OVMMثؑحؙ׮䧭⸆  ^ ^ ^ ͜ͷଞɺύϥϝʔλͷOVMMνΣοΫ΋Մೳʢྫɿ)BOET0OCʣ 4FUUFSͰOVMMνΣοΫʂ
  7. !4MGK !(FUUFS !4FUUFS QVCMJDDMBTT)BOET0O\ QSJWBUF4USJOHJOGP QVCMJDTUBUJDWPJENBJO 4USJOH<>BSHT \ )BOET0OUBSHFUOFX)BOET0O 

    UBSHFUTFU*OGP 䧭⸆  MPHJOGP UBSHFUHFU*OGP  ^ ^ MPHͷΫϥεม਺͕҉໧తʹ࡞੒͞ΕΔʂ
  8. ରԠ͢Δ-PHHFSͷछྨ w !$PNNPOT-PH
 PSHBQBDIFDPNNPOTMPHHJOH-PH w !-PH
 KBWBVUJMMPHHJOH-PHHFS w !-PHK
 PSHBQBDIFMPHK-PHHFS

    w !-PHK
 PSHBQBDIFMPHHJOHMPHK-PHHFS w !4MGK
 PSHTMGK-PHHFS w !94MGK
 PSHTMGKFYU9-PHHFS  ͢΂ͯɺQSJWBUFTUBUJDpOBMͳ
 Ϋϥεม਺ͱͯ͠ॳظԽ͞ΕΔ
  9. !4MGK !"MM"SHT$POTUSVDUPS !(FUUFS QVCMJDDMBTT)BOET0OB\ QSJWBUF4USJOHJOGP QVCMJDTUBUJDWPJENBJO 4USJOH<>BSHT \ )BOET0OBUBSHFUOFX)BOET0OB 䧭⸆

     MPHJOGP UBSHFUHFU*OGP  ^ ^ ͜ͷଞɺpOBM !/PO/VMM ͳϑΟʔϧυͷͨΊͷҾ਺͖ͭίϯε τϥΫλ΍ɺσϑΥϧτίϯετϥΫλɺϑΝΫτϦϝιου΋ ࡞੒Մೳʢྫɿ)BOET0OC )BOET0Oʣ ϑΟʔϧυͷҾ਺͖ͭίϯετϥΫλ͕ ҉໧తʹ࡞੒͞ΕΔʂ
  10. !4MGK !"MM"SHT$POTUSVDUPS !5P4USJOH QVCMJDDMBTT)BOET0O\ QSJWBUF4USJOHOBNF QSJWBUF4USJOHTUBUF QVCMJDTUBUJDWPJENBJO 4USJOH<>BSHT \ )BOET0OUBSHFUOFX)BOET0O

    +BWB%P 劦䌽  MPHJOGP UBSHFUUP4USJOH  ^ ^ <NBJO>*/'0KBWBEPIBOET0OVTF-PNCPL)BOET0O )BOET0O OBNF+BWB%P TUBUFࡳຈ  UP4USJOH ͕ϑΟʔϧυͷঢ়ଶΛจࣈྻͰฦ͢
  11. !4MGK !"MM"SHT$POTUSVDUPS !&RVBMT"OE)BTI$PEF !(FUUFS QVCMJDDMBTT)BOET0O\ QSJWBUF4USJOHOBNF QSJWBUF4USJOHTUBUF QVCMJDTUBUJDWPJENBJO 4USJOH<>BSHT \

    )BOET0OUBSHFUOFX)BOET0O +BWB%P 劦䌽  )BOET0OUBSHFUOFX)BOET0O +BWB%P 劦䌽  MPHJOGP UBSHFU UBSHFUUP4USJOH  MPHJOGP UBSHFU UBSHFUUP4USJOH  MPHJOGP DPOUBJOT UBSHFUFRVBMT UBSHFU  ^ ^ ΦϒδΣΫτ͕஋ҰகͰൺֱͰ͖Δ FRVBMT IBTI$PEFͷத਎͕࡞੒͞ΕΔʣ
  12. !4MGK !"MM"SHT$POTUSVDUPS !&RVBMT"OE)BTI$PEF !(FUUFS !5P4USJOH !'JFME%FGBVMUT NBLF'JOBMUSVF MFWFM"DDFTT-FWFM13*7"5&  QVCMJDDMBTT)BOET0O\

    4USJOHOBNF 4USJOHTUBUF QVCMJDTUBUJDWPJENBJO 4USJOH<>BSHT \ )BOET0OUBSHFUOFX)BOET0O +BWB%P 劦䌽  )BOET0OUBSHFUOFX)BOET0O +BWB%P 劦䌽  MPHJOGP UBSHFU UBSHFUUP4USJOH  MPHJOGP UBSHFU UBSHFUUP4USJOH  MPHJOGP DPOUBJOT UBSHFUFRVBMT UBSHFU  ^ ^ ΞΫηεम০ࢠ͕ແ͍͚ΕͲ΋ QSJWBUF pOBM
  13. !4MGK !"MM"SHT$POTUSVDUPS !%BUB QVCMJDDMBTT)BOET0O\ QSJWBUF4USJOHOBNF QSJWBUF4USJOHTUBUF QVCMJDTUBUJDWPJENBJO 4USJOH<>BSHT \ WBMKVHT4USFBNPG

     OFX)BOET0O +BWB%P 劦䌽  OFX)BOET0O 幪靼+BWB 匌❨  OFX)BOET0O +BWB⹈䓼⠓JO猧衝⾱ 匌❨  OFX)BOET0O ꟼآٍغ 㣐ꢻ  OFX)BOET0O 䀤㿊+BWBِ٦ؠ⠓ 䀤㿊  OFX)BOET0O 䎢䃊+6( 䎢䃊  OFX)BOET0O 擓劤+BWB⹈䓼⠓ 擓劤   DPMMFDU $PMMFDUPSTUP-JTU  KVHTTUSFBN GPS&BDI JUFNMPHJOGP JUFNUP4USJOH  ^ ม਺͕ࢀর͢ΔΦϒδΣΫτܕͰ pOBMͳϩʔΧϧม਺Λ࡞੒ʂ ʢ5ZQF4DSJQUͷWBMͱಉ͡ʣ
 Լͷ৔߹ɺKVHTͷܕ͸-JTU)BOET0O
  14. !4MGK !5P4USJOH !#VJMEFS QVCMJDDMBTT)BOET0O\ QSJWBUF4USJOHOBNF !4JOHVMBS QSJWBUF-JTU4USJOHTFNJOBST QVCMJDTUBUJDWPJENBJO 4USJOH<>BSHT \

    )BOET0O#VJMEFSCVJMEFS)BOET0OCVJMEFS  )BOET0OUBSHFSCVJMEFSOBNF +BWB%P  TFNJOBS "QBDIF8JDLFU  TFNJOBS 4USFBN-BNCEB  TFNJOBS XBLF  TFNJOBS MPNCPL  CVJME  MPHJOGP UBSHFSUP4USJOH  ^ !#VJMEFSΛ͚ͭΔ͚ͩͰ #VJMEFSύλʔϯΛ࣮૷Մೳʂ !4JOHVMBS͸$PMMFDUJPOม਺Λ
 ݸͣͭ௥ՃͰ͖ΔΑ͏ʹ͢Δ
  15. w !6UJMJUZ$MBTT
 ΠϯελϯεԽͷ཈੍ʢ)BOET0Oʣ w !$MFBOVQ
 $MPTBCMFͳΦϒδΣΫτͷࣗಈDMPTFʢ)BOET0Oʣ w !4ZODISPOJ[FE
 ฒྻॲཧ༻ͷTZODISPOJ[FEϒϩοΫ࡞੒ʢ)BOET0Oʣ w

    !8JUI
 JNNVUBCMFΦϒδΣΫτ༻ͷXJUIϝιου࡞੒ʢ)BOET0Oʣ w !"DDFTTPST
 HFUUFSTFUUFSͷϝιουνΣʔϯԽɺ'MVFOUΠϯλʔϑΣʔε తͳ໊শઃఆʢ)BOET0Oʣ 
  16. ݸਓతʹࠇຐज़ײ͕ڧ͍ͱࢥ͏΋ͷ  w !&YUFOTJPO.FUIPE
 ม਺ͷܕΛΩʔʹͨ͠TUBUJDϝιουͷม਺΁ͷ݁߹ʢ)BOET0Oʣ w !%FMFHBUF
 ϝιουॲཧͷϑΟʔϧυΦϒδΣΫτ΁ͷҕৡʢ)BOET0Oʣ w !4OFBLZ5ISPXT


    νΣοΫྫ֎ͷඇνΣοΫྫ֎Խʢ)BOET0Oʣ w !)FMQFS
 ϔϧύʔΫϥεͷΠϯελϯεԽলུʢ)BOET0Oʣ w PO)PHF!@@ !1JZP 
 Ξϊςʔγϣϯͷ෇༩ʢ)BOET0Oʣ