|
Scala example source code file (mock.scala)
The Scala mock.scala source codeimport scala.tools.reflect._ import java.util.concurrent.Callable import java.io.Closeable object Test { // It'd be really nice about now if functions had a common parent. implicit def interfaceify(x: AnyRef): UniversalFn = UniversalFn(x) def runner(x: Runnable) = x.run() def caller[T](x: Callable[T]): T = x.call() def closer(x: Closeable) = x.close() def main(args: Array[String]): Unit = { var counter = 0 val closure = () => { counter += 1 println("Hi, thanks for calling: that makes " + counter + " times.") counter } val int1 = closure.as[Runnable] val int2 = closure.as[Callable[Int]] val int3 = closure.as[Closeable] runner(int1) caller(int2) closer(int3) } } Other Scala examples (source code examples)Here is a short list of links related to this Scala mock.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.