文章列表
scala作为一门dsl语言,可以说隐式转换功劳不少,原本想自己写一个例子的,结果在github(https://gist.github.com/1078092)看到了一个觉得不错,可以分享
package sample
import java.util.{TimerTask, Timer}
/**
* 以下一段java的调用代码
*/
object TimerDemo extends Application {
new Timer().schedule(new TimerTask {
def run() {
println("He ...
scala currying
- 博客分类:
- scala
def threeNumberSum(x: Int, y: Int, z: Int) = x + y + z
def threeNumberSumCurrying(x: Int)(y: Int)(z: Int) = x + y + z
def twoNumberSum = threeNumberSumCurrying(1)_
assert(threeNumberSumCurrying(1)(2)(3) == threeNumberSum(1, 2, 3))
assert(twoNumberSum(2)(3) == threeNumberSum(1, ...
第一了解完传名参数,就想起了写log的代码,为了避免不合理的写日志带来的开销,经常需要使用LOG.isDebugEnabled()判断后才写日志
//传名参数方法
def debug1(log: => String) {
if (logLevel <= DEBUG) println(log)
}
//普通的Sting参数方法
def debug2(log: String) {
if (logLevel <= DEBUG) println(log)
}
反编译看看
public void debug1(Func ...