JAVA9 new Features--syntax improvements: try Statements

Source: Internet
Author: User
1. Examples of Use

Before Java8, we were used to dealing with the closing of resources:

In Java 8, you can implement automatic shutdown of resources, but all resources that must be closed after execution must be initialized in a try clause, or the compilation does not pass. As shown in the following example:

In Java 9, it is easier to write a try with a resource statement, and we can use a resource that has already been initialized in a try clause, when the resource is final:



Still Silicon Valley interviewer Song Hongkang
Links: https://www.jianshu.com/p/f5c746fecd81
Source: Pinterest
Copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source.

JAVA9 new Features--syntax improvements: try Statements

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.