New/strange Java “try()” syntax?

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

    That is called with a try with resources. in a try with resources, any kind of closable stream declared in the resources section will be closed after the try statement is done. So it pretty much is a

    try{
    InputStream is;
    //Stuff
    }finally{
    is.close()
    }
    

提交回复
热议问题