æ¨æ¥ã®çºè¡¨è³æã§ãï¼è³æï¼https://t.co/GKPhtBKprx #kanjava
â Toy (@mdstoy) 2024å¹´7æ31æ¥
é¢ã¸ã£ã'24 7æ度 - connpass ã®ã·ã§ã¼ãã»ãã·ã§ã³ã§åºã¦ãããã¿ããæ¡ä»¶æ¼ç®åã®äºé ç®ã¨ä¸é ç®ãéãåã§ãåããã¨ããããã¤ãã®è¨èªä»æ§è§£èª¬ã
Â
ãã®æåã¯ãªããªã®ãï¼
§15.25. Conditional Operator ? :
ããããä¸é æ¼ç®å ? : ã®åã®ä»æ§ã«ã¤ãã¦ã¯Javaè¨èªä»æ§ã® §15.25. Conditional Operator ? : ãèªã¿è§£ãå¿ è¦ãããã
Â
第äºé ã¨ç¬¬ä¸é ã®åã®çµã¿åããã§ããããããã®ã ãã©ããçµã¿åããã«ããã©ãããåã«ãªãã®ãã¨ãã表ãæ²è¼ããã¦ãããä¾ã®å ´åã¯"Fizz"ãStringåã§ããããããã¯ã¾ãã£ã¨Objectåã¨ããæ±ãã«ãªã£ã¦ Table 15.25-A. Conditional expression type (Primitive 3rd operand, Part I) ããã第äºé ãObjectåã§ç¬¬ä¸é ãintåã®å ´åãlub(Object,Integer) åã«ãªãã¨åããã
Â
ãã® lub(Object,Integer) ã¨ã¯ä½ãã¨ãããã¨ãªã®ã ãã©ãÂ
§4.10.4. Least Upper Bound ã«è¨è¼ããã£ã¦åç §åã®éåã®æå°ä¸é(least upper bound = lub)ã®ãã¨ã§ããããµãã¤ã®åç §åã®ä¸çªå ·ä½çãªå ±éã®ã¹ã¼ãã¼ã¯ã©ã¹ã¨æã£ã¦ãããã°è¯ãã
Â
lub(Object,Integer) ã¨ãããã©ããä¸è¨ä¾ã§ã¯ãã®Objectã®é¨åã¯Stringåã ã£ããããã§ã¯Stringåã¨Integeråã®å ±éã®ã¹ã¼ãã¼ã¯ã©ã¹ã¨èãã¦ãããã°è¯ãã¦ãæ¹ä¾¿ã§è¨ãã°ããã¯Objectåã¨ãããã¨ã«ãªãã
Â
ãã㧠System.out.println(Object) ã大ä¸å¤«ã§ãString str = (i % 3 == 0 ? "Fizz" : i); ã¯ãã¡ãªçç±ãåããã ãããStringåã®å¤æ°ã«Objectåãä»£å ¥ãããã¨ããããã¡ãªããã§ããã
ãªããSystem.out ã¯PrintStreamåãªã®ã§ã©ããªã¡ã½ããããããã¯Â
PrintStreamåã®javadoc ãåç §ããã¨è¯ãã
Â
æ£ç¢ºãªå
å ã»ã©æ¹ä¾¿ã§è¨ãã°Objectåã§ããã¨è¨ã£ããæ£ç¢ºãªã¨ããã¯ã©ããªã®ãï¼
ãã㯠Object & Comparable<?> & Constable & ConstantDesc & Serializableå ã¨ãªãã
Â
ãã® & ãã¤ãåã¯Â §4.9. Intersection Types ã§è§£èª¬ããã¦ãããæ¥æ¬èªã ã¨äº¤å·®åãªã©ã¨å¼ã°ãããJavaã®åã·ã¹ãã ã¯classã®åä¸ç¶æ¿ãinterfaceã®è¤æ°å®è£ ãå¯è½ã¨ãªã£ã¦ãããã¸ã§ããªã¯ã¹ã®å¢çãªã©ã®æå®ã§ã¯&ãç¨ãã¦ãã®classãç¶æ¿ãã¤ã¤ããã®interfaceãå®è£ ãã¦ããåå¤æ° T ã¿ãããªæå®ããããã¨ãã§ããã
Â
æ®å¿µãªããé常ã®å¤æ°å®£è¨ã§ã¯äº¤å·®åã§ã®å¤æ°å®£è¨ã¯ã§ããªãããã¡ã½ããã¹ã³ã¼ãã®åå¤æ°ãåæ¨è«ããããvarãç¨ãããããã¨æ示çã§ã¯ãªãã交差åãç¨ãããã¨ãã§ããã
Â
ãã㧠Stringåã確èªãã¦ã¿ãããjavadocãè¦ãã¨
ãã¹ã¦ã®å®è£ ãããã¤ã³ã¿ãã§ã¼ã¹:
ã¨æ¸ããã¦ããã
Â
Integerã®æ¹ã確èªãã¦ã¿ããã
ãã¹ã¦ã®å®è£ ãããã¤ã³ã¿ãã§ã¼ã¹:
ãã®å ±éé¨åãæ¬ãã ã㨠Object & Comparable<?> & Constable & ConstantDesc & Serializableå ã«ãªãã¨ããããã§ããã
Â
ç´°ãããã¨ã¯ãã¦ãããSystem.out.println(Object) ã«é£ããããã¨ãã§ããã
ã¾ã¨ã
æ£å¼å称ãããããªãJavaã®ä»æ§ã 好ã 好ã 大好ã
Â
åè
lub ã®æ¨è«ãæ°ã«ãªãæ¹ã¯ãã®è¨äºããããã