Javaã®ã¸ã§ããªã¯ã¹ã¯ãã¾ããç©ãã§ã¯ãªã
å æ¥ãèªåãæ¸ãã
ã«å¯¾ããåå¿ã¨ãã¦ããJavaã®ãããªã¾ããç©ã®ã¸ã§ããªã¯ã¹ã¨æ¯è¼ããã®ã¯é©åã§ãªãããJavaã®ã¸ã§ããªã¯ã¹ã¨æ¯è¼ããã®ã¯é©åã§ãªããï¼ããããC#ã(C++çï¼2017/09/24追è¨ï¼)ã®è¨èªã¨æ¯è¼ãã¦ï¼ã¨ãã£ã ã³ã¡ã³ããããã¤ãè¦ããã¾ããï¼ã¯ã¦ãªããã¯ãã¼ã¯ã³ã¡ã³ãããã¤ãã¿ã¼ãªã©ã§ï¼ãããããããã§ã¯ããã®ãããªè¨èª¬ãããé©åã§ãªããã¨ãããã¨ãè¨ãããã§ãããªããmethaneæ°ã¨ã® 対話ã«ã¤ãã¦ã¯æ¢ã«çµãã£ããã®ãªã®ã§ãããã¨ã¯é¢ä¿ããã¾ããã
ãããããJavaã¸ã§ããªã¯ã¹ã¯ãéçåä»ãé¢æ°åè¨èªã§æ¢ã«ä¸è¬çã§ãã£ããã©ã¡ã¼ã¿å¤ç¸ãJavaã«è¿½å ããç®çã§å°å ¥ããã¾ããï¼C++ãã³ãã¬ã¼ãã®ãããªãã®ãJavaã«è¿½å ããããã ã¨æã£ã¦ãã人ãããããããã¾ããããããã¯å®æ ã«ãã£ã¦ãã¾ããï¼ãå®éãJava Genericsã®å身ã®Generic Javaã®ããã«å身ã§ããPizzaã®è«æã§ãMartin Odersky*1ã¯ãPizzaã¯Javaã«ãã©ã¡ã¼ã¿å¤ç¸ï¼parametric polymorphismï¼ãªã©ãå°å ¥ãããã®ã§ãããã¨ãæè¨ãã¦ãã¾ãã
ãã®ããã©ã¡ã¼ã¿å¤ç¸ã¨ããç¨èªã¯ãåçè«ã®åéã§åºã使ããã¦ããç¨èªã§ãåã«ãã£ã¦ã³ã¼ãããã©ã¡ã¼ã¿åã§ããã¨ããæ§è³ªãæãã¾ããéè¦ãªã®ã¯ããã©ã¡ã¼ã¿å¤ç¸ï¼ã¸ã§ããªã¯ã¹ã¨å義ï¼ã§ã¯ããã®ãããªãåã«ãã£ã¦ãã©ã¡ã¼ã¿åãããã³ã¼ãã表ç¾ã§ãã¦ããªããã¤ãã®æ´åæ§ãéçã«ãã§ãã¯ã§ããã¨ããç¹ãæ¬è³ªã§ãã£ã¦ã åãã©ã¡ã¼ã¿ãå®è¡æã«åå¾ã§ãã ã¨ãã ç¹å®ã®åå¼æ°ã«å¯¾ãã¦ç¹æ®åã§ãã ã¨ããã£ãæ§è³ªã¯ãããã¾ã§ å®è£ æ¹å¼ ã«ãã£ã¦å¾ããã追å ã®ã¡ãªããã§ããã¨ãããã¨ã§ããããã¦ã追å ã®ã¡ãªããããªãã¨ããã ãã§ãJavaã¸ã§ããªã¯ã¹ãç´ãç©ã ã¨ã主張ããã®ã¯ãJavaã¨C#ããããã¯Javaã¨C++ã¨ãããç¥ããªã人ãèªãã®ç¡ç解ã示ãã¦ããã«éããªãããå´é£¯ã¢ãã®è¨èª¬ã ã¨ãããã¨ã§ãã
ã¾ããå®è¡æã«åãã©ã¡ã¼ã¿æ å ±ãæã£ãããç¹å®ã®åãã©ã¡ã¼ã¿ã«é¢ãã¦ç¹æ®åã§ããã¨ããã®ã¯ä¾¿å©ã§ãããã©ã³ã¿ã¤ã ã®å®è£ ãå¤§å¹ ã«è¤éåãã¾ãï¼å®è¡æã«ããã©ã¡ã¼ã¿å¤ç¸ãæ±ããªããã°ãããªãã®ã§ï¼ãä¸æ¹ã§ãå®è¡æã«åãã©ã¡ã¼ã¿æ å ±ãæããªããã°ãã©ã³ã¿ã¤ã ã®åã·ã¹ãã ãããç¨åº¦ç¡è¦ãã¦è¨èªã®åã·ã¹ãã ãæ¡å¼µããããã§ãï¼Scalaãå ¸åä¾ï¼ã
å¥ã®ä¾ã¨ãã¦ã¯ãJavaã¯2016å¹´ã«ãåã·ã¹ãã ãå¥å ¨ã§ãªããã¨ã証æãããããåãã§ãã¯ã決å®ä¸è½ã§ãããã¨ã証æãããããã¦ãã¾ãããã©ã³ã¿ã¤ã ã®åã·ã¹ãã ã¯å¥ãªã®ã§ããããã®åé¡ã«ã¤ãã¦ãã©ã³ã¿ã¤ã ãå½±é¿ãåãããã¨ã¯ããã¾ãããä¸æ¹ã§ãC#ãã¯ããã¨ãã.NETè¨èªã§ã¯ãè¨èªã®åã·ã¹ãã ã¨ã©ã³ã¿ã¤ã ã®åã·ã¹ãã ãããªãè¿ããããè¨èªã®åã·ã¹ãã ã«æ¬ é¥ãè¦ã¤ããã¨ããããç´æ¥ã©ã³ã¿ã¤ã ã«å½±é¿ãä¸ããããããããã¾ãã
ãã®ããã«ãã¸ã§ããªã¯ã¹ã®å®è£ æ¹å¼ã¯ããããå¾å¤±ãããã®ã§ãã©ã¡ããããã¨ãã決ãã¤ãããããã®ã§ã¯ããã¾ããã両æ¹ã®æ§è³ªã«ã¤ãã¦ãã¡ãã¨ç解ããä¸ã§ãã©ã¡ãã®æ¹å¼ãæ¯æããã決ããã®ã¯ãã¡ããããã§ããããã®åã«è²ã åå¼·ãã¹ããã¨ãããã¨æãã¾ãã
以ä¸ã2017/09/24追è¨
ç¹å®ã®åãã©ã¡ã¼ã¿ã«é¢ãã¦ç¹æ®åã§ãããã¨ããã®ã®æ義ãä¼ãã£ã¦ããªãã£ãã®ã§æ¸ãã¨ã
class G[T] { def puts(x: T) = println(x) }
ããã£ãã¨ãã¦ã
G[Int]
ã«å¯¾ãã¦ã¯ã
class G_Int{ def puts(x: Int) = println(x) }
ã®ãããªå¹ççãªã³ã¼ããçæãããï¼ãããã¯ã§ããï¼ã¨ãããã¨ãæãã¦ãã¾ããä»åãå¥ã«å®è¡æåæ å ±ã®ã¿ãåé¡ã«ããããã§ã¯ããã¾ããã
Javaã®ã¸ã§ããªã¯ã¹ã¯ãã¾ããç©ãã§ã¯ãªã - kmizuã®æ¥è¨b.hatena.ne.jpRTTI(å®è¡æåæ å ±)ã¯ä½ã®é¢ä¿ããªãã§ããçè ã¯æ ¹æ¬çãªã¨ããã§åéããã¦ãã¾ãããï¼ãScalaã®ã¸ã§ããªã¯ã¹ã ã¨forãã¤ã³ã©ã¤ã³åã§ããã«ç³é ããçç±ãèãã¦ã¿ã¾ããããJavaãScalaã®ã¯ãã ã®Castã®Sugarã§ãã
2017/09/24 10:58
ä¸è¨ã®éããç¹ã«åéããã¦ãã¾ãããã¾ããScalaã®for
ãé
ãçç±ã«ã¤ãã¦ããä½ãåéãããã¦ãã¨æãã¾ãããã£ã¹ãã®æ§æç³è¡£ã ã¨ãããããªè¦æ¹ã«ã¤ãã¦ã¯ãä»åã®æ¬æãèªãã§ãã ããã¨ãããè¨èªã®åã·ã¹ãã ã®è©±ããã¦ããã®ã«ããããªããå®è£
ã¨ãã¦ã®ãããã£ã¹ããã¯ããããã¨ã«è¨åããã¦ãã®ã§ããã®äºã¤ã®éãã«ã¤ãã¦ãã£ããèãã¦ã¿ãããã¨è¯ããã¨ã