New/strange Java “try()” syntax?

后端 未结 8 511
一个人的身影
一个人的身影 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:32

    The try-with-resources statement is a try statement that declares one or more resources. A resource is an object that must be closed after the program is finished with it. The try-with-resources statement ensures that each resource is closed at the end of the statement. Any object that implements java.lang.AutoCloseable, which includes all objects which implement java.io.Closeable, can be used as a resource.

提交回复
热议问题