Created
April 15, 2014 01:10
-
-
Save dmahapatro/10694012 to your computer and use it in GitHub Desktop.
Trait to handle try-with-resources feature for Java 8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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