1.switch支持String類型
package date201336;
/**
* JDK7新特性
* @author Shoper
* switch支持String類型參數,依然不支持long類型
*/
public class JDK7 {
public static void main(String[] args) {
String str="shoper";
switch (str) {
case "shoper":
System.out.println("I'm shoper");
break;
default:
break;
}
}
}
現在java 的switch不僅支持byte int char 等數據類型還支持String類型了。現在世面教程都是說switch支持String類型,那麼這句話就得要看JVM的版本了,1.7以上的話是能支持的哦。這點跟Mircosoft的C#靠齊了.Jdk1.8據說即將發佈,不知道到時候還有什麼新技術發佈。
1.int支持X_X
package date201336;
/**
* JDK7新特性
*
* @author Shoper int支持0_0形式
*/
public class JDK7 {
static int num = 111_111;
public static void main(String[] args) {
System.out.println(num);
}
}
int類型加_分開數字了,這個新特性不錯。