1. ã¯ããã«: Scalaãšã¯
Scalaã¯ããŒãã³ã»ãªããŒããŒã«ããéçºãããé«ã¬ãã«ãªèšèªã§ããªããžã§ã¯ãæåãšé¢æ°åããã°ã©ãã³ã°ã®ç¹æ§ãå ŒãåããŠããŸãããã®æè»æ§ãšåŒ·åãªè¡šçŸåã§ããœãããŠã§ã¢éçºãããå¹ççã§æ¥œããããããã®éå ·ãšããŠæ³šç®ã济ã³ãŠããŸãã
Scalaã¯Javaããã®åœ±é¿ãå€ãåããŠãããJavaã®ã³ãŒããçŽæ¥å©çšããèœåããããŸãããŸããScalaã¯Javaãšåæ§ã«JVM(Java Virtual Machine)äžã§åäœããŸãã
以äžã§ã¯ãScalaã®ç¹æ§ãJavaãšã®æ¯èŒãScalaãåŠã¶ã¹ãçç±ããããŠScalaéçºã®åºæ¬ã³ã³ã»ããã«ã€ããŠè§£èª¬ããŸãã
1.1 Scalaã®ç¹æ§ãšã¡ãªãã
Scalaã¯ãã®èšèªèšèšãšããŠãéçåä»ãããªããžã§ã¯ãæåãé¢æ°åããã°ã©ãã³ã°ãçµã¿åãããããšã«ãããããã°ã©ã ã®ççž®ãšå¹çåãå³ãç¹æ§ãæã£ãŠããŸãããããã®ç¹æ§ã«ãããéçºè ã¯äžè²«æ§ã®ããæœè±¡åãçšããŠé«åºŠãªã³ãŒããç°¡æœã«æžãããšãå¯èœã§ãã
ãŸããScalaã¯æ¢åã®Javaã®ã³ãŒããã©ã€ãã©ãªãšã®äºææ§ããããŸããããã«ãããæ¢åã®Javaãããžã§ã¯ããžã®çµ±åã容æãšãªããæ¢åã®ç¥èã掻ãããŸãã
ããã«ãScalaã®åŒ·åãªåã·ã¹ãã ã¯ã³ãŒãã®å®å šæ§ã確ä¿ãããã°ãæ©æã«çºèŠããå©ããšãªããŸãããŸããåæšè«æ©èœã«ãããåã®æ瀺çãªå®£èšãçç¥ã§ããã³ãŒãéã®åæžã«è²¢ç®ããŸãã
1.2 Javaãšã®æ¯èŒ
Scalaã¯Javaãšåããéçåä»ãèšèªã§ãããJVMäžã§åäœããç¹ã§ã¯å ±éããŠããŸããããããScalaã«ã¯é¢æ°åããã°ã©ãã³ã°ã®ç¹æ§ãå«ãŸããŠãããããå€æ§ãªæœè±¡åãæè»ãªã³ãŒãè¡šçŸãå¯èœã§ãã
ãŸããScalaã®ã³ãŒãã¯Javaã®ããã«è©³çŽ°ãªå宣èšãå¿ é ã§ã¯ãªããåæšè«æ©èœãå©çšããŠã³ãŒãã®ç°¡æœåãå¯èœã§ããããã«ãããåãåŠçãè¡ãã³ãŒãã§ããScalaã®æ¹ãçããã·ã³ãã«ãªã³ãŒããšãªããŸãã
äžæ¹ã§ãScalaã®åŠç¿æ²ç·ã¯Javaãšæ¯èŒããŠããæ¥ã§ãããé£æ床ã¯é«ããšãããŸãããããããã®å€æ§ãªè¡šçŸåãé«ãæœè±¡åèœåããŸãæ¢åJavaã³ãŒããšã®äºææ§çãèæ ®ãããšãScalaã®ç¿åŸã¯éåžžã«äŸ¡å€ããããšèšããŸãã
1.3 ScalaãåŠã¶ã¹ãçç±
ScalaãåŠã¶çç±ã®äžã€ãšããŠããã®å€æ§ãªè¡šçŸåãæããããŸããScalaããªããžã§ã¯ãæåãšé¢æ°åããã°ã©ãã³ã°ã®æŠå¿µãèåããŠãããããããã°ã©ã ã®è¡šçŸåãåäžããŸãã
ãŸããScalaã¯JVMäžã§åäœããŸãã®ã§ãJavaãšåçã®ããã©ãŒãã³ã¹ãç¶æãã€ã€ãããå¹ççãªããã°ã©ãã³ã°ãå¯èœã§ããããã¯ãšãããã倧èŠæš¡ãªããŒã¿åŠçã«å¿ èŠãªé«åºŠãªäžŠååŠçãåæ£åŠçãå®çŸããããã«ã¯éèŠã§ãã
æåŸã«ãScalaã®ããã®è±å¯ãªã©ã€ãã©ãªããã¬ãŒã ã¯ãŒã¯ãååšããŸããäŸãã°ãApache SparkãAkkaãšãã£ãã©ã€ãã©ãªã¯Scalaã¢ããªã±ãŒã·ã§ã³ã®éçºãå©ãã倧èŠæš¡ããŒã¿åŠçãªã©ã«å©çšãããŠããŸãã
1.4 Scalaéçºã®åºæ¬ã³ã³ã»ãã
Scalaéçºã®åºæ¬ã³ã³ã»ããã®äžã€ãšããŠããªããžã§ã¯ãæåãšé¢æ°åã®ãã£ãããšããç解ãæ±ããããŸããScalaã¯ãããäºã€ã®ããã°ã©ãã³ã°ã¹ã¿ã€ã«ã®ãã©ã³ã¹ããšããèšèªã§ãã®ã§ãã©ã¡ããç解ããããšãéåžžã«éèŠã§ãã
ãŸããScalaã³ãŒãã®å質ãä¿ã€äžã§ã¯ã䜿ãããªããåã·ã¹ãã ã®ç解ãéèŠãšãªããŸããå¹æçãªæœè±¡åãšã³ãŒãã®å®å šæ§ã確ä¿ããããã«ãåã·ã¹ãã ã®ç解ãšé©åãªäœ¿çšãæ±ããããŸãã
ããã«ãScalaéçºè ã«ãšã£ãŠã¯Scalaã®ãã«ãããŒã«ã§ããsbtã®ç解ãäžå¯é¿ã§ããsbtã¯ã·ãŒã ã¬ã¹ãªéçºäœéšãæäŸããŠãããã©ã€ãã©ãªã®äŸåé¢ä¿ã®ç®¡çããã¹ãããããã€ã¡ã³ããè¡ãããšãã§ããŸãã
2. Scalaç°å¢æ§ç¯ã®åææ¡ä»¶
2.1 å¿ èŠãªããŒããŠã§ã¢ãšãœãããŠã§ã¢
Scalaéçºã®ããã«ã¯ããã®å®è¡ç°å¢ãæ§ç¯ããããã®é©åãªããŒããŠã§ã¢ãšãœãããŠã§ã¢ã®æºåãå¿ èŠã§ãããããã«ã¯ããŸãäžã€ç®ãšããŠãã¢ããªã±ãŒã·ã§ã³ã®å®è¡ã«ååãªã¡ã¢ãªãšåŠçèœåãæã€çšŒåå¯èœãªã³ã³ãã¥ãŒã¿ãå¿ èŠã§ãããã®é¢ã§ã¯ãå€ãã®çŸä»£ã®ããŒãœãã«ã³ã³ãã¥ãŒã¿ã¯Scalaéçºã®èŠä»¶ãæºãããŠããŸãã
äºã€ç®ããœãããŠã§ã¢ã®é¢ã§ã¯ãScalaã¯Javaããã®æŽŸçèšèªã§ãããããJavaã®éçºãããã§ããJava Development Kit(JDK)ãå¿ èŠã§ãããŸããScalaæ¬äœãšãã«ãããŒã«ã®sbtïŒScala Build ToolïŒã®ã€ã³ã¹ããŒã«ãå¿ èŠãšãªããŸãã
ãããã察å¿ããããŒãžã§ã³ã¯å€åãããããå ¬åŒãµã€ãã«ãŠææ°ã®æ å ±ã確èªããŠãã ããã
2.2 Java Development Kit (JDK)ã®èª¬æ
Java Development KitïŒJDKïŒã¯ãJavaã¢ããªã±ãŒã·ã§ã³ã®éçºã«å¿ èŠãªãœãããŠã§ã¢ã®äžã€ã§ãScalaã®å®è¡ç°å¢ã®æ§ç¯ã«ãå¿ èŠãšãªããŸããJDKã«ã¯ãJavaã®ã³ã³ãã€ã©ãšJavaã©ã³ã¿ã€ã ç°å¢ãå«ãŸããŠããŸãã
倧äºãªç¹ãšããŠã¯ãJDKã«ã¯å€ãã®ããŒãžã§ã³ãååšããŸãããScalaã®éçºã«ã¯JDK8ã®ã€ã³ã¹ããŒã«ãæšå¥šãããŠããŸããããã¯ããã®åŸã®ããŒãžã§ã³ã«ã¯ããã«ãããŒã«ã§ã®äžå ·åã®å¯èœæ§ãããããã§ãã
ãããã®ç¹ãç解ããé©åãªããŒãžã§ã³ã®JDKãæºåããããšãScalaã®ç°å¢æ§ç¯ã®ã¹ã ãŒãºãªé²è¡ã«è³ããã§ãããã
2.3 JDKã®ã€ã³ã¹ããŒã«ãšãã§ãã¯
Java SE Development Kit 8ïŒJDK8ïŒã¯ãå ¬åŒã®ãµã€ãããããŠã³ããŒãå¯èœã§ããããŠã³ããŒãåŸãæé ã«åŸã£ãŠã€ã³ã¹ããŒã«ãè¡ããŸãããã
次ã«ãJDKã®ã€ã³ã¹ããŒã«ãæ£åžžã«å®äºãããã確èªããããã®æé ã«ã€ããŠèª¬æããŸãããã®ããã«ã¯ãã³ãã³ãããã³ãããéãã`java -version`ãšããã³ãã³ããå®è¡ããŸãã
çµæãšããŠãã€ã³ã¹ããŒã«ããJDKã®ããŒãžã§ã³æ å ±ã衚瀺ãããããã«ããJDKã®ã€ã³ã¹ããŒã«ãæ£åžžã«å®äºããããšã確èªã§ããŸãã
2.4 ç°å¢å€æ°ã®èšå®
æåŸã«ãJDKã®ã€ã³ã¹ããŒã«åŸãã³ã³ãã¥ãŒã¿å šäœã§Javaã³ãã³ãã䜿çšã§ããããã«ããããã«ç°å¢å€æ°ã®èšå®ãå¿ èŠã§ããããã«ã¯ãã·ã¹ãã ç°å¢å€æ°ã®`PATH`ã«JDKã®binãã©ã«ããžã®ãã¹ãè¿œå ããŸãã
ãã®èšå®ãè¡ãããšã§ãJavaã³ãã³ããä»»æã®å Žæããå®è¡ããããšãå¯èœã«ãªããŸããããã«ãã£ãŠãScalaã®ã³ã³ãã€ã«ãå®è¡çãã¹ã ãŒãºã«è¡ããããã«ãªããŸãã
以äžãScalaã®ç°å¢æ§ç¯ã®åææ¡ä»¶ã§ãããããã®æ¡ä»¶ãæºãããå°é£ãæé€ããããšãScalaã®ç°å¢æ§ç¯ã®æåã«ç¹ãããŸãã
3. Scalaãšãã«ãããŒã«sbtã®ã€ã³ã¹ããŒã«
Scalaã®ç°å¢æ§ç¯ã«ãããŠæ¬ ãããªãèŠçŽ ããScalaæ¬äœãšãã«ãããŒã«sbtã®ã€ã³ã¹ããŒã«ã§ããä»åã¯ããããã®è©³çŽ°ãªã€ã³ã¹ããŒã«æ¹æ³ãé ãè¿œã£ãŠè§£èª¬ããŠãŸãããŸãã
Javaãã掟çããScalaã¯é »ç¹ãªã³ã³ãã€ã«ãå¿ èŠãšãªããŸãããsbtãèªåçã«ãã®åœ¹å²ãæãããŠãããŸãã®ã§ãéçºå¹çãå€§å¹ ã«åäžããŸãã
ããã§ã¯ãå ãã¯Scalaæ¬äœã®ã€ã³ã¹ããŒã«ããå§ããŠãŸãããŸãããã
3.1 Scalaæ¬äœã®ã€ã³ã¹ããŒã«æ¹æ³
Scalaæ¬äœã¯ãå ¬åŒãµã€ãããããŠã³ããŒãå¯èœã§ããå ¬åŒããŠã³ããŒãããŒãžã«ã¢ã¯ã»ã¹ãããDownload ScalaããšèšèŒããããšãªã¢ãããOSã«åãããã€ã³ã¹ããŒã©ãŒãããŠã³ããŒãããŸãããã
ããŠã³ããŒãããã€ã³ã¹ããŒã©ãŒãå®è¡ããããšã§ãèªåçã«ã€ã³ã¹ããŒã«ãéå§ãããŸããéäžã§è¡šç€ºãããæ瀺ã«åŸããå¿ èŠãªèšå®ãè¡ã£ãŠãã ããã
ãªããScalaã¯Javaäžã§åäœããŸãã®ã§ãäºåã«JDKã®ã€ã³ã¹ããŒã«ãå¿ èŠãšãªããŸããé©åãªããŒãžã§ã³ã®JDKãã€ã³ã¹ããŒã«æžã¿ã§ããããšã確èªããŸãããã
3.2 ãã«ãããŒã«sbtã®æŠèŠ
sbtã¯ãScalaã®ãã«ãããŒã«ã§ãããšåæã«ãã©ã€ãã©ãªç®¡çæ©èœãæã€ããŒã«ã§ããsbtãå©çšããããšã§ãScalaã®ã³ã³ãã€ã«ããã©ã€ãã©ãªã®ãªã³ã¯ãªã©ãèªåçã«è¡ã£ãŠãããŸãã
sbtãååšããããšã§ãéçºè ã¯è€éãªãã«ããäŸåé¢ä¿ã®è§£æ±ºãªã©ãã解æŸãããã³ãŒãã®äœæã«å°å¿µããããšãå¯èœãšãªããŸãã
ãŸããsbtã«ã¯ã€ã³ã¿ã©ã¯ãã£ãã¢ãŒããçšæãããŠãããé²è¡äžã®ãã«ããäžæããããšãªããæ°ããªã¿ã¹ã¯ã®å®è¡ãå¯èœã§ãã
3.3 sbtã®ã€ã³ã¹ããŒã«ãšã»ããã¢ãã
sbtã®ã€ã³ã¹ããŒã«ãScalaãšåæ§ãå ¬åŒãµã€ãããããŠã³ããŒããå¯èœã§ããå ¬åŒããŠã³ããŒãããŒãžã蚪åãããDownload sbtããšèšèŒãããŠãããšãªã¢ãããé©åãªã€ã³ã¹ããŒã©ãããŠã³ããŒãããŠã€ã³ã¹ããŒã«ãé²è¡ããŠãŸãããŸãããã
sbtã®ã»ããã¢ããã¯ãååèµ·åæã«è¡ãããŸããã€ã³ã¹ããŒã«åŸã«ãsbtãã³ãã³ããå®è¡ãããšãsbtãèªåçã«ã»ããã¢ãããéå§ããŸãã
ãªããsbtãScalaåæ§Javaäžã§åäœããŸãã®ã§ãJDKã®ã€ã³ã¹ããŒã«ããã³èšå®ãé©åã«è¡ãããŠããããšã確èªããŠãã ããã
3.4 åäœç¢ºèªãšãã©ãã«ã·ã¥ãŒãã£ã³ã°
ã€ã³ã¹ããŒã«ãå®äºããããå¿ ãåäœã®ç¢ºèªãè¡ããŸããããå ·äœçãªç¢ºèªæ¹æ³ã¯ããscalaããšãsbtãã³ãã³ãã端æ«ã§å®è¡ããæ£åžžã«åäœãããã確èªããŸãã
ãããæ£åžžã«åäœããªãå Žåã¯ããšã©ãŒã¡ãã»ãŒãžãåèã«ãã©ãã«ã·ã¥ãŒãã£ã³ã°ãè¡ã£ãŠãã ãããScalaãsbtã®ããŒãžã§ã³éãããŸãã¯JDKã®èšå®äžåãªã©ãèããããŸãã
ãããŸã§ã§ãScalaãšãã«ãããŒã«sbtã®ã€ã³ã¹ããŒã«ã«ã€ããŠè§£èª¬ããŸãããäžã€äžã€ã®æé ãçå®ã«é²ããŠãScalaã®éçºç°å¢ãæŽããŸãããã
4. å®è·µçãªScalaã®ã³ãŒãã®æžãæ¹ãšå®è¡ã®æµã
ãã®ã»ã¯ã·ã§ã³ã§ã¯Scalaã®ã³ãŒãã®æžãæ¹ãšãã®å®è¡ã®æµãã詳现ã«è§£èª¬ããŸããå ·äœçã«ã¯ãScalaã®ã³ãŒãã®åºæ¬çãªèšè¿°æ¹æ³ãã³ã³ãã€ã«ãšå®è¡ã®æé ããããŠäžè¬çãªãšã©ãŒå¯ŸåŠæ³ã«ã€ããŠåŠã³ãŸãã
4.1 .scalaãã¡ã€ã«ã®äœæãšåºæ¬çãªã³ãŒãã£ã³ã°
.scalaãã¡ã€ã«ã®äœæã¯éåžžã«ã·ã³ãã«ã§ãããŸãã¯ãã奜ããªããã¹ããšãã£ã¿ãéããScalaã®ã³ãŒããæžãå§ããŸããã³ãŒãããã¹ãŠèšè¿°ãããããã¡ã€ã«ã.scalaæ¡åŒµåã§ä¿åããŸãã
Scalaã®åºæ¬çãªã³ãŒãã£ã³ã°ã«ãŒã«ãèŠããããšã¯ãå¹ççãªã³ãŒããæžãããã«éèŠã§ãããŸããScalaã¯éçã«åä»ããããèšèªã§ããããããå€ãã®å Žåãå€æ°ãé¢æ°ã®è¿ãå€ã®åãæå®ããå¿ èŠã¯ãããŸããããªããªããScalaã³ã³ãã€ã©ãããããæšæž¬ããŠãããããã§ãã
ãŸããScalaã®æ§æã¯æ¯èŒçã·ã³ãã«ã§ãèªã¿ããããç¹åŸŽã§ããJavaãšåæ§ã«ãScalaããªããžã§ã¯ãæåããã°ã©ãã³ã°ãšé¢æ°åããã°ã©ãã³ã°ããµããŒãããŠããŸãã
4.2 ã³ã³ãã€ã«ã®æµã
Scalaã®ã³ãŒããæžãããã次ã¯ãããã³ã³ãã€ã«ããå¿ èŠããããŸããã³ã³ãã€ã«ãšã¯ããœãŒã¹ã³ãŒãïŒäººéãç解ã§ããã³ãŒãïŒããã€ãã³ãŒãïŒJVMãç解ã§ããã³ãŒãïŒã«å€æããããã»ã¹ã®ããšã§ãã
Scalaã®ã³ãŒããã³ã³ãã€ã«ããããã«ã¯ãã³ãã³ãããã³ããã§compile
ã³ãã³ããå®è¡ããŸãããããŠããšã©ãŒããªããã°ã.scalaãã¡ã€ã«ãã³ã³ãã€ã«ããããã€ãã³ãŒãã«å€æãããã®ã§ãã
ãã®ããã»ã¹ãéããŠããœãŒã¹ã³ãŒãäžã®ã¿ã€ããã¹ãæ§æãšã©ãŒãªã©ã®åé¡ãæ©æã«æ€åºã§ããŸãããã®ãããã³ã³ãã€ã«ã¯ã³ãŒãã®å質ãç¶æããããã«äžå¯æ¬ ãªããã»ã¹ã§ãã
4.3 ããã°ã©ã ã®å®è¡
ã³ã³ãã€ã«ãæåãããã次ã¯Scalaã®ããã°ã©ã ãå®è¡ããŸãããã®äœæ¥ã¯ãã³ãã³ãããã³ããã§run
ã³ãã³ããå®è¡ããã ãã§ãã
ãããŠãã³ãŒããåé¡ãªãå®è¡ãããã°ãæå®ããåºåã衚瀺ãããŸããããã¯ãã³ãŒããæ£ããåäœããŠããããšã確èªããããã®éèŠãªã¹ãããã§ãã
ãªããScalaã®ããã°ã©ã ãå®è¡ããéã«ã¯ãJVMïŒJava Virtual MachineïŒãå¿ èŠã§ããããšãå¿ããªãã§ãã ãããScalaã®ã³ãŒãã¯ãæçµçã«JVMäžã§ãã€ãã³ãŒããšããŠå®è¡ãããã®ã§ãã
4.4 åºæ¬çãªãšã©ãŒã®å¯ŸåŠæ³
Scalaã®ã³ãŒããæžããŠãããšãæ§ã ãªãšã©ãŒã«ééããå¯èœæ§ããããŸãããããã®ãšã©ãŒã¯äž»ã«ãã³ã³ãã€ã«ãšã©ãŒãå®è¡æãšã©ãŒãè«çãšã©ãŒã®ïŒã€ã«åããããŸãã
ã³ã³ãã€ã«ãšã©ãŒã¯æ§æãæååãäºçŽèªã®äœ¿çšæ¹æ³ãªã©ã«é¢ãããšã©ãŒã§ãããã«ä¿®æ£ãå¯èœãªãã®ãã»ãšãã©ã§ããå®è¡æãšã©ãŒã¯ããnullããªããžã§ã¯ããžã®ã¢ã¯ã»ã¹ãååšããªãã¡ãœããã®åŒã³åºããªã©ãã³ã³ãã€ã«æã«ã¯æ€åºã§ããªããšã©ãŒã§ãã
äžæ¹ãè«çãšã©ãŒã¯ãããã°ã©ã ãæ£åžžã«åäœããŠããããã«èŠããããæåŸ éãã®çµæãåŸãããªãå Žåã«çºçããŸãããããã®ãšã©ãŒãä¿®æ£ããããã«ã¯ãã³ãŒãã詳现ã«ã¬ãã¥ãŒããããã°ã©ã ã®ãããŒã培åºçã«ç解ããå¿ èŠããããŸãã
5. IDEã®éžæãšèšå®
Scalaã®éçºãå¹çåããããã«ã¯ãçµ±åéçºç°å¢ïŒIDEïŒã®æŽ»çšãæ¬ ãããŸãããIDEãå©çšããããšã§ãã³ãŒãã£ã³ã°ãã³ã³ãã€ã«ããããã°ãšãã£ãéçºäœæ¥ã®ãã¹ãŠãäžã€ã®ãã©ãããã©ãŒã ã§è¡ãããšãã§ããŸãã
ä»åã¯ãScalaã®éçºã«ããããã®IDEã«ã€ããŠæ·±å ããããã®å ·äœçãªèšå®æ¹æ³ãã玹ä»ããŸãã
ãªããããã§çŽ¹ä»ããæ å ±ã¯Scalaéçºåå¿è ã察象ãšãããã®ã§ãããããã©ã³ãšã³ãžãã¢ã«ãšã£ãŠãåèã«ãªãå 容ãšãªã£ãŠããŸãã
5.1 Scala察å¿IDEã®æŠèŠ
Scalaãæ±ãããã®IDEã¯ããã€ãååšããŸãããç¹ã«ãEclipseãããIntelliJ IDEAãã®2ã€ãäž»æµãšãªã£ãŠããŸãã
Eclipseã¯Javaãäž»ãªå¯Ÿè±¡ãšããæ§ã ãªãã©ã°ã€ã³ãçµã¿èŸŒãã§æè»ãªã«ã¹ã¿ãã€ãºãå¯èœãªIDEã§ãScalaãã©ã°ã€ã³ãå©çšããããšã§Scalaã®éçºãå¯èœã§ãã
äžæ¹ãIntelliJ IDEAã¯JetBrains瀟ãéçºããIDEã§ãJavaã ãã§ãªããScalaãå§ããšããå€æ°ã®ããã°ã©ãã³ã°èšèªã«å¯Ÿå¿ããŠããŸããScalaéçºã«ãããã·ã³ã¿ãã¯ã¹ãã€ã©ã€ããèªåè£å®ãªã©ã®æ©èœãå å®ããŠãããååŠè ããäžçŽè ãŸã§å¹ åºãå©çšãããŠããŸãã
5.2 EclipseãšIntelliJ IDEAã®æ¯èŒ
Scalaéçºã«ãããŠãEclipseãšIntelliJ IDEAã¯ãããããäžé·äžçããããŸãã
Eclipseã¯ç¡åã§å©çšã§ãããã©ã°ã€ã³ãéããå€æ©èœæ§ãç¹åŸŽã§ãããã«ããæ§ã ãªèšèªã«å¯Ÿå¿ããéçºç°å¢ãæ§ç¯ã§ããŸãããããããã©ã°ã€ã³ã®ç®¡çãèšå®ãè€éã§ããããåå¿è ãžã®é²è¡ã®è¶³ãããšãªãããšããããŸãã
ããã«å¯ŸããŠIntelliJ IDEAã¯Scalaéçºåãã®æ©èœãããã©ã«ãã§åãã£ãŠãããScalaç¹æã®æ§æãç解ããç確ãªè£å®ãæäŸããŠããããããScalaéçºã«éäžã§ããŸãããã ããå®å šãªæ©èœãå©çšããããã«ã¯ææçã®è³Œå ¥ãå¿ èŠãšãªããŸãã
5.3 IntelliJ IDEAã®ããŠã³ããŒããšã€ã³ã¹ããŒã«
Scalaéçºäœéšã®åäžãç®æããªããåçŽè ããäžçŽè ãŸã§å¹ åºãæ¯æãããŠããIntelliJ IDEAã®å©çšãããããã§ãã
IntelliJ IDEAã¯å ¬åŒãµã€ãããããŠã³ããŒãã§ããŸããCommunityçã¯ç¡æã§ãScalaã®åºæ¬çãªéçºç°å¢ãåããŠããŸããUltimateçã¯ææã§ãããè¿œå ã®ããŒã«ããã¬ãŒã ã¯ãŒã¯ãå©çšããããšãå¯èœã§ãã
ããŠã³ããŒãããåŸãã€ã³ã¹ããŒã©ãŒã®æ瀺ã«åŸã£ãŠã€ã³ã¹ããŒã«ãè¡ããŸããããåºæ¬çã«ã¯æ瀺ã«åŸã£ãŠé²ãã°åé¡ãããŸãããã”Download featured plugins”ã®éžæç»é¢ã§ã¯”Scala”ã«ãã§ãã¯ãå ¥ããŠãããŸãããã
5.4 IntelliJ IDEAã§ã®Scalaéçºç°å¢ã»ããã¢ãã
IntelliJ IDEAã®ã€ã³ã¹ããŒã«ãå®äºãããã次ã¯Scalaã®éçºç°å¢ãã»ããã¢ããããŠãããŸãã
ãŸããIntelliJ IDEAãèµ·åãããCreate New ProjectããéžæããŸããç¶ããŠãScalaãã«ããŽãªãŒãšãsbtããéžæããProject SDKã§JDKãéžæããŸããããã§éèŠãªã®ã¯ã”Use auto-import”ã«ãã§ãã¯ãå ¥ããããšã§ããããã«ãããsbtãäŸåæ§ãèªåã§è§£æ±ºããŠãããŸãã
以äžã§Scalaã®éçºç°å¢ã®ã»ããã¢ããã¯å®äºã§ããããããã¯ãIntelliJ IDEAã«ããå¹ççãªScalaéçºã楜ããã§ã¿ãŠãã ããã
6. ããããåé¡ãšãã®è§£æ±ºç
Scalaã®ç°å¢æ§ç¯äžã«ééãããããããªãåçš®ã®åé¡ãšãã®è§£æ±ºçã«ã€ããŠèª¬æããŸãããããã®è§£æ±ºçã¯å®éã«ScalaãŠãŒã¶ãŒãçµéšãããã®ã«åºã¥ããŠããŸãã®ã§ãåã ã®åé¡ãçŽ æ©ãå æããããã®ã¬ã€ãã©ã€ã³ãšããŠã圹ç«ãŠãã ããã
åé¡ã®çš®é¡ã¯ãã€ã³ã¹ããŒã«äžã®äžè¬çãªãšã©ãŒãã³ã³ãã€ã«ãšã©ãŒãå®è¡ãšã©ãŒã«åããããŸãããã®æé ãšè§£æ±ºçãé ã«å ¥ããŠããããšã§ãåé¡è§£æ±ºã®æéãççž®ãããããšãã§ããŸãã
ããã«ãScalaã®ãšã©ãŒã«å¯Ÿãã解決çãææ°ã®æ å ±ã«ã€ããŠã¯ãæ§ã ãªã³ãã¥ããã£ããªãœãŒã¹ãããåŸãããšãã§ããŸããèªå·±è§£æ±ºãé£ããåé¡ã«çŽé¢ãããšããã³ãã¥ããã£ã®åãåãã䟡å€ããããŸãã
6.1 ã€ã³ã¹ããŒã«äžã®äžè¬çãªãšã©ãŒãšå¯ŸåŠæ³
Scalaã®ã€ã³ã¹ããŒã«äžã«ééããäžè¬çãªåé¡ã®äžã«ã¯JDKãèŠã€ãããªããsbtã®ã€ã³ã¹ããŒã«ãšã©ãŒçããããŸããJDKã«ã€ããŠã¯ãJDK8ããæšå¥šãããŠããããŒãžã§ã³ã§ããããšãå¿ããªãã§ãã ãããsbtã®åé¡ã¯ã€ã³ã¹ããŒã©ã®ãã°ããããã¯ãŒã¯åé¡ãäžè¬çã§ãã
ãããã®åé¡ã®è§£æ±ºçãšããŠããŸãJDKã®ã€ã³ã¹ããŒã«ã確èªããããã«ãã³ãã³ãããã³ããã§`java -version`ãå®è¡ããŠã¿ãŠãã ãããããã倱æããå Žåãå床JDKã®ã€ã³ã¹ããŒã«ãè¡ã£ãŠã¿ãŠãã ããããŸãsbtã®åé¡ã«ã€ããŠã¯ãå ¬åŒãµã€ãããææ°çãããŠã³ããŒããåã€ã³ã¹ããŒã«ããããšã«ãã解æ¶ããå¯èœæ§ããããŸãã
察å¿ã«è¿·ã£ãå Žåã¯ãå ¬åŒããã¥ã¡ã³ããScalaã®ã³ãã¥ããã£ã掻çšããŸããããå€ãã®ãŠãŒã¶ãŒãééããåé¡ã®è§£æ±ºçãããã§èŠã€ããããšãäžè¬çã§ãã
6.2 ã³ã³ãã€ã«ãšã©ãŒã®äŸãšè§£æ±ºæ³
Scalaã³ãŒããã³ã³ãã€ã«ã§ããªãç¶æ³ãçããå Žåãããã¯ãã°ãã°ææ³ã®èª€ããåãšã©ãŒãªã©ããæ¥ããã®ã§ããããã§éèŠãªã®ã¯ããšã©ãŒã¡ãã»ãŒãžãããèŠãŠç解ããããã«åºã¥ããŠé©åãªå¯ŸåŠãè¡ãããšã§ãã
Scalaã®ãšã©ãŒã¡ãã»ãŒãžã¯éåžžã«æ å ±éãå€ããããŸãããŸãªãã³ããé ãããŠããŸãããããã®ãšã©ãŒã¡ãã»ãŒãžãç解ããé©åã«è§£æããèœåã¯Scalaéçºè ã«ã¯å¿ é ãšèšããŸãããšã©ãŒã¡ãã»ãŒãžãææããç®æãèŠçŽããScalaã®ææ³ã«éåããŠããªããå床ãã§ãã¯ããããšã倧åã§ãã
ãŸããScalaã®åŠç¿è ã»éçºè ãšããŠãScalaã®å ¬åŒããã¥ã¡ã³ããŒã·ã§ã³ãé »ç¹ã«åç §ããããšããå§ãããŸããé¢é£ãããããã¯ã®è©³çŽ°ãªèª¬æã¯ãåé¡ãç解ã解決ããæå©ãã«ãªãã§ãããã
6.3 å®è¡ãšã©ãŒã®äŸãšè§£æ±ºæ³
å®è¡ãšã©ãŒã¯ããã°ã©ã ãæåŸ éãã«åäœããªãç¶æ³ãæããŸããããã«ã¯ã©ã³ã¿ã€ã ãšã©ãŒãã¯ã©ã¹ãèŠã€ãããªããªã©ã®åé¡ãå«ãŸããŸããäœæããã³ãŒãèªèº«ã«ãã°ãååšããå Žåãããã°ãã©ã€ãã©ãªãå®è¡ç°å¢ã«åé¡ãããå ŽåããããŸãã
ãã®é¡ã®ãšã©ãŒã®è§£æ¶ã«ã¯ããšã©ãŒã¡ãã»ãŒãžãæ·±ãç解ããåé¡ãçºçããå ·äœçãªã³ãŒãéšåãç¶æ³ãç¹å®ããããšãå¿ èŠãšãªããŸãããŸããæå®çãªè§£æ±ºçãç¡ãå Žåãè€æ°ã®èŠ³ç¹ãããã®åé¡ãç解ããããšããããšãéèŠã§ãã
解決çãšããŠã¯ããŸãã¯å ¬åŒããã¥ã¡ã³ããåç §ãããŸãScalaã®ãŠãŒã¶ãŒã³ãã¥ããã£ã§ã¢ããã€ã¹ãæ±ããããšãæå¹ãªã¢ãããŒãã§ãããŠãŒã¶ãŒã³ãã¥ããã£ã«ã¯è±å¯ãªçµéšãšç¥èãæã€ãŠãŒã¶ãŒãå€æ°ååšããŸãã圌ãã®ç¥èã¯ãããªããçŽé¢ããåé¡ã®è§£æ±ºçãèŠã€ããã®ã«å€§ãã«åœ¹ç«ã€ã§ãããã
6.4 ãã©ãã«ã·ã¥ãŒãã£ã³ã°ã®ããã®ã³ãã¥ããã£ãšãªãœãŒã¹
Scalaã®åé¡ã®è§£æ±ºãå©ããã³ãã¥ããã£ãšãªãœãŒã¹ã¯æ°å€ãååšããŸãããããã¯åé¡è§£æ±ºã®äŸ¡å€ããæ å ±æºãšãªããŸãããŠãŒã¶ãŒãã©ãŒã©ã ãã©ã€ããã£ãããQ&Aãµã€ããªã©ããŸããŸãªå Žæã§Scalaã«é¢ãã話é¡ãè°è«ãããŠããŸãã
äžæ¹ãå ¬åŒããã¥ã¡ã³ãã¯æãä¿¡é Œæ§ã®é«ããªãœãŒã¹ã§ããããããéå ¬åŒã®ãã©ãã«ã·ã¥ãŒãã£ã³ã°ã¬ã€ããããªãã®åé¡è§£æ±ºã®äžå©ãšãªãã§ãããã
ãããã®ãªãœãŒã¹ãå©çšããŠãScalaç°å¢æ§ç¯æã®åé¡ã解決ããããäžå±€ã®Scalaéçºã¹ãã«ã¢ããã«åœ¹ç«ãŠãŠãã ããã
åèæç®
![](https://www.sejuku.net/blog/wp-content/uploads/2019/06/scala-inst.jpg)