Created
December 16, 2011 12:59
-
-
Save j5ik2o/1485960 to your computer and use it in GitHub Desktop.
ベタなLoanパターン
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
object Loan { | |
def using[A <: { def close() }, B](resource: A)(func: A => B): B = | |
try { | |
func(resource) | |
} finally { | |
if (resource != null) resource.close() | |
} | |
} | |
using(new FileInputStream("hoge.txt")){ fis => | |
fis.read(...) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment