New/strange Java “try()” syntax?

后端 未结 8 510
一个人的身影
一个人的身影 2021-01-30 16:17

While messing around with the custom formatting options in Eclipse, in one of the sample pieces of code, I saw code as follows:

/**
 * \'try-with-resources\'
 */         


        
8条回答
  •  盖世英雄少女心
    2021-01-30 16:49

    it was added in java 7. It is called try with resources. Try with resources statement feature was introduced in java 7 version. Try with resource statement is a try statement that declares one or more statements. A resource is an object that must be closed after the program is finished with it.

    Before java 7 we use finally block to close the resources that we have used in our program. In finally block we have to close all the resources manually that we have used in our program. For more information you can visit try with resources

提交回复
热议问题