æ¨æ¥ãJava 7th moon 富山ãéå¬ããã¾ãããåå è 21åã¨å°è¦æ¨¡ãªãããä¼å ´ã¯é常ã«çãä¸ããã¾ããããããåã楽ããããããªã«æ¥½ããã®ã¯ä¹ ãã¶ãã ãã¹ãã¼ã«ã¼ããã¦ãã ãã£ãçãããåå ãã¦ãã ãã£ãçãããæ¬å½ã«ãããã¨ããããã¾ãï¼
LT(ã©ã¤ããã³ã°ãã¼ã¯)ã§æã®ãã¿ãå¼ã£å¼µãåºãã¦Semicolonless Javaããã£ãã®ã ãã©ãLTãªã®ã§æéããªãä¸çªã¢ãã¤é¨åãä¼ããããªãã£ãã®ã§ã¡ãã£ã¨æ¸ãã¦ãããã
æ´å²
Semicolonless Java(ã»ãã³ãã³ã¬ã¹Java)ã¯Javaã®ãµãã»ããã§ãJavaè¨èªãããã ã²ã¨ã¤ã»ãã³ãã³ãåãé¤ããã ãã®ããã°ã©ã è¨èªã ã
ãã®è¨èªèªä½ã¯1996å¹´ã«Javaããªãªã¼ã¹ãããã¨åæã«å®è£ ãåå¨ãããã誰ã«ãç¥ããã¦ããªãã£ãããã®è¨èªãçºè¦ãããã®ã¯2010/3/21ã§å ´æã¯ç±æµ·ãjava-ja温æ³ã¨ããã¤ãã³ãã®2æ¥ç®ã®ãã¨ã ã£ãã
Pythonã«ã¯ã³ã©ã¤ãã¼ã¨å¼ã°ãããã®ããã£ã¦(参考)西尾ããã第ä¸äººè ãªã®ã ãã©ã端çã«èª¬æããã°ãé常ã¯æ¹è¡ãå¿ é ã§ããPythonã«ããã¦ãæ¹è¡ãè¡ãã1è¡ã ãã§ã©ã®ããã«ããã°ã©ã ãæ¸ããã¨ãã話é¡ã§ããã
Semicolonless Javaã¯ãã®Pythonã®ã¯ã³ã©ã¤ãã¼ã®æµããæ±²ããã¨ã¯ãããJavaã¯ã»ãã³ãã³ãç¨ãã¦1è¡ã«ãã«ãã¹ãã¼ãã¡ã³ãã§ãããã§ãè¨è¿°ã§ãããJavaã«ãããã¯ã³ã©ã¤ãã¼çãªã¢ãã¨ã¯ä½ãããããã»ãã³ãã³ãç¨ããªãã¨ããç¸ãã ã£ãã
æã¨å¼
Pythonã®ã¯ã³ã©ã¤ãã¼ãæ¸ãä¸ã§ã¯ãæ:Statementãã¨ãå¼:Expressionãã®åºå¥ãéè¦ã§ãããæ®æ®µã®ããã°ã©ãã³ã°ã®ä¸ã§ã¯ããããè¨èªä»æ§ã¯ãã¾ãæèããªããã®ã ããããããã£ãã説æããã°ãæ:Statementãã¯å¤ãæããªãããå¼:Expressionãã¯å¤ãæã¤ãã¨ãã£ãã¨ããããã®èãæ¹ã¯Semicolonless Javaã«ãéããã
ä¾ãã°Javaã§
Object o = null;
ã¨ããå ´åã®nullã®é¨åããã®é¨åã«æ¸ãããã®ã¯ä½ãï¼ã¨ãã£ãã¨ãã«ãå¤ããæã¤ã¢ãã¯æ¸ãããããå¤ããæããªããã®ã¯æ¸ããªãããã ããã®å¤ãæã¤ãã®ãæããªããã®ã¯Javaã®æ§æä¸ã¯æ確ã«åºå¥ãããããããããæ:Statementãã¨ãå¼:Expressionããªããã ã
Javaã§ã¯ãæãã«ã¯å¹¾ã¤ãã®ç¨®é¡ããã*1ããã®ãã¡
- ãã¼ã«ã«å¤æ°å®£è¨æ
- åºæ¬foræ
- breakæ
- continueæ
- returnæ
- throwæ
- å¼æ (å¼ã«ã»ãã³ãã³ãã¤ãã¦æã¨ãããã®)
ã¯ã»ãã³ãã³ãå¿ è¦ã¨ãªããã¤ã¾ãSemicolonless Javaã§ã¯å©ç¨ã§ããªãã
- ãããã¯
- ãã¼ã«ã«ã¯ã©ã¹å®£è¨
- ifæ
- assertæ
- switchæ
- whileæ
- doæ
- æ¡å¼µforæ
- synchronizedæ
- tryæ
ã¯ã»ãã³ãã³ãªãã«ç¨ãããã¨ãã§ããã
次ã«ãå¼ãã¯è©ä¾¡ãã¤ã¾ãå®è¡ãããã¨ãã«çµæã表ãããã®çµæã¨ããã®ã¯
- å¤æ°
- å¤
- ãªã(void)
ã®3種é¡ããã£ã¦Javaè¨èªä»æ§3ç15ç« ãå¼ãããå¼ç¨ããã¨
å¼æï¼Â§14.8ï¼ä»¥å¤ã®ãã¹ã¦ã®ã³ã³ããã¹ãã§ã¯ï¼ãã®å¼ãä½ãã表ãã¦ããªããã°ãªããªãããï¼ä½ã表ããªãå¼ã¯å¼æã§ãã使ç¨ãããã¨ãã§ããªã
ä¾ãã°ã¡ã½ããå¼ã³åºãã¯ãå¼ããªã®ã ããæ»ãå¤ãvoidã®ã¡ã½ããã®å ´åãä»£å ¥ã®å³è¾ºãªã©ã§ç¨ãããã¨ãã§ããªãã
List list = new ArrayList(); Object o = list.clear(); // ã³ã³ãã¤ã«ã¨ã©ã¼
ã¤ã¾ããJavaã¨ããè¨èªã®æ§æçã«ã»ãã³ãã³ãªãã§ä½¿ç¨å¯è½ãªã®ã¯ã»ãã³ãã³ãªãã§ç¨ãããããã¤ãã®æã¨ãvoid以å¤ã®å¼ã¨ãããã¨ã«ãªããããã«ãå¼ãã§ããã°ã©ãã³ã°ãããã¨ããã®ããã¼ãã«ãªãããã ã
ã¡ã½ãããä½ã
Javaã§ã¡ã½ããå¼ã³åºãã¯ãå¼ããªã®ã ãã©ããæ»ãå¤ãvoidã®ã¡ã½ããã¯å¼æã§ãã使ããªããããã¦å¼æã¯ã»ãã³ãã³ãå¿ è¦ãã¤ã¾ããæ»ãå¤ãvoidã®ã¡ã½ããã¯Semicolonless Javaã§ã¯å¼ã³åºããã¨ãã§ããªããã¨ãæå³ããã*2
ããã¦æ»ãå¤ãããã¡ã½ããã®å ´åã¯ãreturnæãã»ãã³ãã³ãªãã§ã¯è¨è¿°ã§ããªããããããããã¡ã½ãããå®ç¾©ãããã¨ãã§ããªãããã®å¶ç´ã®ããããã¤ãã£ããªJavaã®interfaceãå®è£ ãããã¨ãã»ã¼ä¸å¯è½ã§ãããããã«ãã£ã¦å©ç¨ã§ããJavaã®APIã¯å¤§ããå¶éãããã
Semicolonless Javaã§ã¯Javaè¨èªã§ã®ã¡ã½ããã¯æ»ãå¤ãvoidã®ãã®ã ã宣è¨ãããã¨ãã§ããããã¦ãããå¼ã³åºããã¨ã¯ã§ããªãã¨ããç¶æ³ã«ããããã®å¶ç´ä¸ã§ã©ã®ããã«æ§é åããã°ã©ãã³ã°ãããã®ãï¼
Javaè¨èªã§ã¯æ§é åããã°ã©ãã³ã°ã®ããã«ã¯å½ç¶ãªããã¡ã½ãããç¨ããããã®ããã®è¨èªæ©æ§ãªã®ã ãããã ããããã使ããªã以ä¸ãä»ã®æ¹æ³ã§ã¡ã½ããã®ä»£ç¨ã¨ããªããã°ãªããªãã
ããã§ç·¨ã¿åºãããã®ããã³ã¬ã¯ã·ã§ã³ãç¶æ¿ããã¯ã©ã¹ã¨ã³ã³ã¹ãã©ã¯ã¿ã§ã¡ã½ããã®ä»£ç¨ã¨ããææ³ã ã
public class Hoge extends java.util.ArrayList<String> { public Hoge(String in) { if (this.add(in)){} } }
ArrayList<String> ãç¶æ¿ãã Hogeã¯ã©ã¹ãããããã®ã³ã³ã¹ãã©ã¯ã¿ãSemicolonless Javaã§ã®ãã¡ã½ããããªã®ã ãthis.add()ã§èªèº«ã®ã¤ã³ã¹ã¿ã³ã¹ã«ãæ»ãå¤ããadd()ãããããã¨ããã®Hogeã¯ã©ã¹ã®newãã¦ããget()ããã¨å¤ãåãåºããã¨ãã§ããã¨ãã寸æ³ãªã®ã ã
for(Hoge hoge : new Hoge[]{new Hoge("in")}) { if (null == System.out.printf(hoge.get(0))){} }
ãã®Semicolonless Javaã§ã®ãã¡ã½ããããä½ãéã«extendsããåã¯ä½ãããã ããããããã§ã¯ArrayListãç¨ããããMapãç¨ãã¦ãã¼ã«enumãç¨ããã¨åã·ã¹ãã çã«ç¶ºéºã§ã¯ãããå¤ãè¤æ°è¿ãå¿ è¦ããªãã®ã§ããã°SoftReferenceãããã使ãåæãè¯ããããããªããªãã¨æã£ãããããããã¡ã½ããå¼ã³åºãããå¤ãåå¾ããã¾ã§ã«GCã«ã½ããåç §ãååãããå¯è½æ§ãå¦å®ããããªããJavaã®APIãæ¢ãã°ããæé ãªã¯ã©ã¹ãè¦ã¤ãããããããããªããä»å¾ã®ç 究ãå¾ ãããã¨ããã§ããã
ãªãã¸ã§ã¯ãæåã¸ã®éã®ã
ãã¦ãåãã¯Semicolonless Javaã§æ§é åããã°ã©ãã³ã°ããææ³ãæã«ããããã®ãã¡ã½ãããâJavaã§ããã¯ã©ã¹å®£è¨ã ãâãå é¨ã¯ã©ã¹ã¨ãã¦ã¾ã¨ãã¦ã¿ããã
/** èªèº«ãMapã¨ãããã¨ã§ã¤ã³ã¹ã¿ã³ã¹ãã£ã¼ã«ãã表ç¾ãã */ public class ClassSample extends java.util.HashMap<ClassSample.Key, Object> { /** ã¤ã³ã¹ã¿ã³ã¹ãã£ã¼ã«ãã«ã¢ã¯ã»ã¹ãããã¼ */ enum Key { FIELD_1, FIELD_2, } /** * ã¡ã½ããA. * @return Stringå */ public class MethodA extends java.util.ArrayList<String> { /** å¼æ°ãªã */ public MethodA() {/*çç¥*/} /** ãªã¼ãã¼ãã¼ãã¡ã½ãã */ public MethodA(int i) {/*çç¥*/} } /** ã¡ã½ããB */ public class MethodB extends java.util.ArrayList<String> { public MethodB(String str) { if (null == ClassSample.this.put(Key.FIELD_1, str)){} } } }
ãã® ClassSample ã§ã¯Javaã®ã¯ã©ã¹ã®ãããªãã®ã表ç¾ãã¦ã¿ããèªèº«ãMapã¨ãããã¨ã§ã¤ã³ã¹ã¿ã³ã¹ãã£ã¼ã«ãã表ç¾ããå é¨ã¯ã©ã¹ã§ã¡ã½ããã表ç¾ãããã¡ã½ããBã§ã¯ã¡ã½ããå ããã¤ã³ã¹ã¿ã³ã¹ãã£ã¼ã«ãã«å¤ãæ ¼ç´ãã¦ã¿ãã¦ããã
ããããããã¯ãªãã¸ã§ã¯ãæåã®ã¯ã©ã¹è¶³ãå¾ãªãããã®ã¯ã©ã¹ãç¶æ¿ããã¯ã©ã¹ãä½ã£ã¦ãããªã¢ã¼ãã£ãºã ãåããªãã®ã ãSemicolonless Javaã®ã¡ã½ããå¼ã³åºãã¯Javaã§ããnewãªããã ããããã¯éçã«å®ã¾ãããªã¢ã¼ãã£ãºã ããªãã
ããã§ããªã¢ã¼ãã£ãºã ããæ©æ§ãèãã¦ããå¿ è¦ããããã¤ã¾ãnewãåçã«ãããããã ãããçãã¯ãªãã¬ã¯ã·ã§ã³ã ã
ã¾ããç¶æ¿ããã¯ã©ã¹ãä½ã£ã¦ãããã
public class ExClassSample extends ClassSample { /** * ã¡ã½ããAã®ãªã¼ãã¼ã©ã¤ã */ public class MethodA extends java.util.ArrayList<String> { /** å¼æ°ãªã */ public MethodA() {/*çç¥*/} /** ãªã¼ãã¼ãã¼ãã¡ã½ãã */ public MethodA(int i) {/*çç¥*/} } }
ããã¦ããã®ã¯ã©ã¹ã®ã¡ã½ããAãå¼ã³åºãããã ãããªãã¬ã¯ã·ã§ã³ã使ã£ã¦å¼ã³åºãããã«ããã
for (ClassSample c : new ClassSample[]{new ClassSample(), new ExClassSample()}) { if (null==Class.forName(c.getClass().getName()+"$MethodA") .getConstructor(c.getClass()).newInstance(c)){} }
ãã®ããã«ããã¨ãæåã®ã«ã¼ãã§ã¯ClassSample$MethodAãåãã2åç®ã§ã¯ExClassSample$MethodAãåãããã«ãªãããã§ããã
ã¾ã¨ã
- Semicolonless Javaã§ã¯Javaã®æ©æ§ã®ã¡ã½ããã使ããªã
- ã³ã¬ã¯ã·ã§ã³ã¯ã©ã¹ãç¶æ¿ããã¯ã©ã¹ãä½ããã¨ã§ã¡ã½ããã®ä»£ç¨ã¨ãããµãã«ã¼ãã³åããããã¨ãã§ãããæ»ãå¤ãè¿ããã¨ãåºæ¥ã
- ãã®Semicolonless Javaã®ã¡ã½ããã¯ãªãã¬ã¯ã·ã§ã³ãç¨ãããã¨ã§ããªã¢ã¼ãã£ãºã ããããã¨ãã§ãã