Skip to content

Instantly share code, notes, and snippets.

@dmahapatro
Created April 15, 2014 01:10
Show Gist options
  • Save dmahapatro/10694012 to your computer and use it in GitHub Desktop.
Save dmahapatro/10694012 to your computer and use it in GitHub Desktop.
Trait to handle try-with-resources feature for Java 8
import java.io.Closeable
import java.io.IOException
trait Closing {
def closeQuietly(){
try{
println "Closing"
this.close()
} catch (IOException e) {
}
}
}
Closeable clos = new FileInputStream('test.txt')
assert clos.available()
(clos as Closing).closeQuietly()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment