查看Scala编程(控制抽象)我看到了这两个具有相同效果的示例:
1. 高阶函数
def withPrintWriter(file: File, op: PrintWriter => Unit) {
val writer = new PrintWriter(file)
try {
op(writer)
} finally {
writer.close()
}
}
2.咖喱功能
def withPrintWriter(file: File)(op: PrintWriter => Unit) {
val writer = new PrintWriter(file)
try {
op(writer)
} finally {
writer.close()
}
}
它们之间有什么区别?我们能否始终以两种方式获得相同的结果?