Scala finally block closing/flushing resource

后端 未结 3 652
清歌不尽
清歌不尽 2020-12-09 03:23

Is there a better way to ensure resources are properly released - a better way to write the following code ?

        val out: Option[FileOutputStream] = try         


        
3条回答
  •  感情败类
    2020-12-09 04:15

    Have a look at Scala-ARM

    This project aims to be the Scala Incubator project for Automatic-Resource-Management in the scala library ...

    ... The Scala ARM library allows users to ensure opening closing of resources within blocks of code using the "managed" method. The "managed" method essentially takes an argument of "anything that has a close or dispose method" and constructs a new ManagedResource object.

提交回复
热议问题