Java 7 is approaching. Here we will first look at some new practical features, so we can understand them in a simple and clear way.
1) switch, you can no longer use integer types, such as the previous steps:
Switch (someint ){
Case 0: Return zerointresult; break;
Case 1: Return oneintresult; break;
Default: return New brokenswitchexception ("Bad integer ");
}
Now we can.
Switch (somestring ){
Case "Bubba": Return bubbastringresult; break;
Case "Sue": Return suestringresult; break;
Default: return New brokenswitchexception ("odd string! ");
}
2) Try Improvement
Previously:
Try {
} Catch (anyexceptionthrownbythatop aetbto ){
// Handle the exception byfm
} Finally {
Try {
} Catch (exception ignored ){
}
}
Previously it was very troublesome. now:
Try (fileoutputstream Fos = new fileoutputstream (File )){
} Catch (anyexceptionthrownbythatop aetbto ){
}
I no longer use finally.
3) combination of multiple try Methods
Previously:
Try {
} Catch (firstsimilarexception FSE ){
} Catch (secondsimilarexception SSE ){
} Catch (exception ex ){
}
Now we can work together:
Try {
} Catch (firstsimilarexception | secondsimilarexception e ){
} Catch (exception ex ){
}
4) Simplified writing
Previously:
Map <integer, list <string> AMAP = new hashmap <integer, list <string> ();
In Java 7, you can:
Map <integer, list <string> AMAP = new hashmap <> ();
5) Clear long display
Previously:
Long creditcard = 5440444033300005l;
Long phonenumber = listen 5551212l;
Clear statement:
Long creditcard = 5440_4440_3330_0005l;
Long phonenumber = maid;