In the following example, the definition of javaVersion is a
shorthand for the anonymous class definition anonfun0:
object Main extendsApp {
val javaVersion = () => sys.props("java.version")
val anonfun0 = new Function0[String] {
def apply(): String = sys.props("java.version")
}
assert(javaVersion() == anonfun0())
}
Note that Function1 does not define a total function, as might
be suggested by the existence of scala.PartialFunction. The only
distinction between Function1 and PartialFunction is that the
latter can specify inputs which it will not handle.
A function of 0 parameters.
In the following example, the definition of javaVersion is a shorthand for the anonymous class definition anonfun0:
Note that
Function1
does not define a total function, as might be suggested by the existence of scala.PartialFunction. The only distinction betweenFunction1
andPartialFunction
is that the latter can specify inputs which it will not handle.