Sunday, 8 September 2013

Using = in Unit methods

Using = in Unit methods

I'm a bit confused about the Scala's recommended style of using the equal
sign in Unit methods, which one is recommended?
def withPrintWriter(file: File, op: PrintWriter => Unit) {
val writer = new PrintWriter(file)
try {
op(writer)
} finally {
writer.close()
}
}
or
def withPrintWriter(file: File, op: PrintWriter => Unit) = {
val writer = new PrintWriter(file)
try {
op(writer)
} finally {
writer.close()
}
}

No comments:

Post a Comment