- Strings in
switch
statement.
public class StringSwitchCase {
public static void main(String args) {
String day = "SAT";
switch (day) { // switch on String selector
case "MON": System.out.println("Monday"); break;
case "TUE": System.out.println("Tuesday"); break;
case "WED": System.out.println("Wednesday"); break;
case "THU": System.out.println("Thursday"); break;
case "FRI": System.out.println("Friday"); break;
case "SAT": System.out.println("Saturday"); break;
case "SUN": System.out.println("Sunday"); break;
default: System.out.println("Invalid");
}
}
}
- Binary integer literals.
You can exprese liternal value with 0b for (int,long and so). You are also permitted to use underscore (_
) to break the digits to improve the readability
public class BinaryIntegerLiteralTest {
public static void main(String[] args) {
int int2 = 0b01_1010;
System.out.println(int2);
}
}
- Allowing underscores in numeric literals.
- Catching multiple exception types and rethrowing exceptions with improved type checking.
- Automatic resource management in
try
-statement. - Improved type inference for generic instance creation, aka the diamond operator
<>
. - Simplified varargs method declaration.
Comments
Post a Comment