JDK 7ã®æ°æ©è½ Peoject Coinç·¨ï¼ãã®1ï¼
å æ¥ãJDK 7の開発者プレビューã¨ãJDK 7ã«å¯¾å¿ããNetBeans 7.0 Beta 2ããããããªãªã¼ã¹ããã¾ããããã£ãããªã®ã§JDK 7ã®æ°æ©è½ããããããã¤ã¤ãå®éã«NetBeansã使ã£ã¦è©¦ãã¦ã¿ããã¨æãã¾ã*1ã
JDK 7ã®æ°æ©è½ã«ã¤ãã¦ã¯このページã«ä¸è¦§ãã¾ã¨ãããã¦ãã¾ããã¾ãã¯æã身è¿ã¨ãè¨ãããProject Coinããããã£ã¦ã¿ã¾ããããProject Coinã¯ãåå¥ã«ä»æ§åããã»ã©ã§ã¯ãªãç´°ããªææ³ã®å¤æ´ã追å ãªã©ã®å®è£ ãé²ããããã¸ã§ã¯ãã§ããJCPã§ã¯ãJSR 334: Small language enhancementsãã¨ãã¦ç»é²ããã¦ãã¾ãï¼ç¾å¨ãããã¥ã¡ã³ãããã¦ã³ãã¼ãã§ãã¾ãï¼ãç¾å¨ã®ã¨ãããJSR 334ã«ã¯Java SE 7ã«æè¼ããæ°æ©è½ã¨ãã¦æ¬¡ã®ãã®ãæãããã¦ãããããããJDK 7ã§ã¯ãã§ã«å®è£ ãå®äºãã¦ãã¾ãã
- Stringã«ããswitchæ
- 2é²æ°ãªãã©ã«ã¨ã¢ã³ãã¼ã¹ã³ã¢ä»ãæ°å¤ãªãã©ã«
- è¤æ°ä¾å¤ã®ãã£ããããã³ä¾å¤ã®å®å ¨ãªåã¹ãã¼
- åæ¨è«ã«ããã¸ã§ããªã¯ã¹ã®ãªãã¸ã§ã¯ãçæï¼ãã¤ã¢ã¢ã³ãï¼
- ãªã½ã¼ã¹ä»ãã®try-catch
- å¯å¤é·å¼æ°ã使ãã¡ã½ããå¼ã³åºãã®è¦åãæå¶ï¼@SafeVarargsã¢ããã¼ã·ã§ã³ï¼
Stringã«ããswitchæ
ã¾ãStringã使ç¨ããswicthæã«ã¤ãã¦ã§ãããããã¯switchã®æ¡ä»¶ã«æååãªãã©ã«ã使ããããã«ãªã£ãã¨ãããã¨ã§ãã次ã®ãããªæãã§ãã
static void testStringSwitch(String str) { switch (str) { case "hoge": System.out.println("ã»ãã»ã"); break; case "piyo": System.out.println("ã´ãã´ã"); break; default: System.out.println("ããã©ã«ã"); break; } }
strã«nullã渡ããNullPoinerExceptionãã¹ãã¼ããã¾ããããã¯Integerãªã©ã®å ´åã¨åæ§ã§ããã
switchæã®ãã®æ¡å¼µã¯ãç¾æç¹ã§ã¯JVMã«ã¯å½±é¿ãä¸ãã¾ããï¼å°æ¥ãµãã¼ããããå¯è½æ§ã¯ããã¾ãï¼ãJVMã§ã¯switchãæ±ãå½ä»¤ã¨ãã¦lookupswitchã¨tableswitchãããããã§ããããããã¯ä¾ç¶ã¨ãã¦æååãªãã©ã«ããµãã¼ããã¦ãªãã¨ãããã¨ã§ããã§ã¯ã©ããã£ã¦æ¯è¼ãã¦ããã®ãã¨ããã¨ãã³ã³ãã¤ã©ã¯æååããã¤ãã³ã¼ãã·ã¼ã±ã³ã¹ã«å¤æãããããæ¯è¼ã«å©ç¨ãã¦ããã¨ã®ãã¨ã§ã*2ã
2é²æ°ãªãã©ã«
Javaã§ã¯ã"0x"ãæ°å¤ã®åã«ä»ãã¦16é²æ°ã®æ°å¤ã表ããã¨ãã§ãã¾ããJDK 7ã§ã¯ãåããããªæ¹æ³ã§2é²æ°ã®æ°å¤ã表ããã¨ãã§ããããã«ãªãã¾ããã2é²æ°ã¯ãæ°å¤ã®åã«"0b"ã¾ãã¯"0B"ãä»ãã¦è¡¨ç¾ãã¾ãã次ã®ãããªæãã§ãã
int binary = 0b011001; System.out.println(binary); int binary2 = 0B110100; System.out.println(binary2);
åºåã¯ä»¥ä¸ã®ããã«æ®éã®10é²æ°å½¢å¼ã«ãªãã¾ãã
25 52
次ã®ãããªè¡¨è¨ã¯ã§ãã¾ãããããã¯0xã®å ´åã¨åãã§ãã
int binary3 = 0b12345; // ã³ã³ãã¤ã«ã¨ã©ã¼
ã¢ã³ãã¼ã¹ã³ã¢ä»ãæ°å¤ãªãã©ã«
æ°å¤ãªãã©ã«ã«ã¤ãã¦ã¯ããã²ã¨ã¤å¤æ´ãããã¾ããæ°å¤ã®éä¸ã«ã1_234_567ãã®ããã«ã¢ã³ãã¼ã¹ã³ã¢ï¼"_"ï¼ãå ¥ããããããã«ãªã£ããã¨ã§ããããã¯å é¨çã«ã¯æ®éã«ã1234567ãã¨ãã¦æ±ããã¾ããã1,23,567ãã®ãããªåºåãæåä»ãã®æ°å¤ã¨åããããªãã®ã¨èãã¦ããã§ãããããã®å¤æ´ã¯ã³ã¼ãã®å¯èªæ§ãä¸ããããã«æ¡ç¨ããã¾ãããã¢ã³ãã¼ã¹ã³ã¢ã¯é£ç¶ãã¦ä»ãããã¨ãã§ãã¾ãããæ°å¤ã®å é ãæå¾ã«ä»ãããã¨ã¯ã§ãã¾ããã
int withUnderscore = 123_456_789; System.out.println(withUnderscore); int withUnderscore2 = 9_8_7_6_5; System.out.println(withUnderscore2); int withUnderscore3 = 123__456; System.out.println(withUnderscore3);
åºåçµæã¯æ¬¡ã®ããã«ãªãã¾ãã
123456789 98765 123456
次ã®ãããªæ¸ãæ¹ã¯ã³ã³ãã¤ã«ã¨ã©ã¼ã«ãªãã¾ãã
int withUnderscore4 = _123456; // ã³ã³ãã¤ã«ã¨ã©ã¼ int withUnderscore5 = 123456_; // ã³ã³ãã¤ã«ã¨ã©ã¼
é常ã®æ°å¤ãªãã©ã«ã¨åããªã®ã§ã次ã®ãããªãã¨ãã§ãã¾ãã
for (int i = 0; i < 1_00; i++) { ... }
2é²æ°ãªãã©ã«ã16é²æ°ãªãã©ã«ãªã©ã®ä¸ã§ä½¿ããã¨ãã§ãã¾ããããããå é ãæ«å°¾ã«ä»ããã®ã¯ãã¡ã§ãã
int binary4 = 0b0_110_01; int hex = 0x123_abc; //int binary5 = 0b_011001; // ã³ã³ãã¤ã«ã¨ã©ã¼
NetBeansã§ã®æ°å¤ãªãã©ã«ã®èªåå¤æ
æ°å¤ãªãã©ã«ã«é¢é£ãã¦ãNetBeans 7.0ã«ã¯æ°å¤ã®è¡¨è¨ãèªåã§å¤æãã¦ãããæ©è½ã追å ããã¾ãããæ°å¤ã®é¨åã«ã«ã¼ã½ã«ãããå ´åã«ã次ã®ããã«ã³ã¼ããã³ããåºã¦ãä»»æã®åºæ°ã«èªåã§å¤æãã¦ããã¾ããèªåã§è¨ç®ããæéãçããã®ã§å°å³ã«ä¾¿å©ã§ãã
ç¶ãã¯æ¬¡åã«ã