ifæãå¼ã«å¤æãã
Javaã®ifæã¯ãæããªã®ã§å¤ãè¿ãã¾ãããæ¡ä»¶ãè©ä¾¡ããçµæã«å¿ãã¦å¤ãè¿ããå¼ããä½ãã«ã¯ä¸é æ¼ç®åã使ãã¾ãããããããã©ããã¦ãæ°ã«é£ãã!ãã¨ããå¥ç¹ãªäººã®ããã«(ããã®ã?)ãããããã°ifããå¼ãã«ãã¦é¢æ°ã®å¼æ°ã«ã¶ã¡ããã ãã§ããã!
System.out.println( new Object() { String x() { if ( true ) { return "a"; } else { return "b"; } }}.x());
å®è¡çµæã§ãã
a
ã¾ããå¯èªæ§ãããã©ã¼ãã³ã¹ã¨ãã«ç¡é§ãå¤ãã®ã§è£½åã³ã¼ã使ã£ããã¯ãã«ãªãããã ãã©ããã¼ãä¼¼ããããªãã¿ã§長い文字列をさくっと作るã£ã¦ããã®ã¯åã«æ¸ãããªã¼ã
Strign str = new StringWriter(){{ for(int i=0;i<100;i++) write("a"); }}.toString();
ãã¡ãã¯ãã¹ãã±ã¼ãã§ãã¾ã«ä½¿ã£ã¦ã¾ãã