Created
October 6, 2011 13:15
-
-
Save takscape/1267370 to your computer and use it in GitHub Desktop.
Scala: ローンパターン2
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 collection.JavaConversions._ | |
import java.net.URL | |
import org.apache.commons.io.IOUtils | |
object scalatest | |
{ | |
def closing[T <: {def close(): Unit}, R](a: T)(f: T => R): R = { | |
try { | |
f(a) | |
} finally { | |
a.close() | |
} | |
} | |
def main(args: Array[String]) | |
{ | |
closing(new URL("http://www.google.com/").openStream) { s => | |
println(IOUtils.toString(s, "UTF-8")) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment