在Scala中,final声明一个成员不能在子类中重写。例如: class Parent {
val a = 1
final val b = 2
}
class Subclass extends Parent {
override val a = 3 // this line will compile
override val b = 4 // this line will not compile
}
... 展开详请
可以定义: implicit def idToSideEffect[A](a: A) = new {
def withSideEffect(fun: A => Unit): A = { fun(a); a }
def |!>(fun: A => Unit): A = withSideEffect(fun) // forward pipe-like
def tap(fun: A => Unit): A = withSideEffect(fun) // public demand & ruby standard
} 然后: calcSomeResult() |!> { rs => logger.info("result is:" + rs) }
calcSomeResult() tap println... 展开详请