scala

trait Function0

[source: scala/Function0.scala]

trait Function0[+R]
extends AnyRef

Function with 0 parameters.

In the following example the definition of currentSeconds is a shorthand for the anonymous class definition anonfun0:

  object Main extends Application {

    val currentSeconds = () => System.currentTimeMillis() / 1000L

    val anonfun0 = new Function0[Long] {
      def apply(): Long = System.currentTimeMillis() / 1000L
    }

    println(currentSeconds())
    println(anonfun0())
  }
Direct Known Subclasses:
Future, Stream.Definite, Reference

Method Summary
abstract def apply : R
override def toString : java.lang.String
Returns a string representation of the object.
Methods inherited from AnyRef
getClass, hashCode, equals, clone, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Method Details
abstract def apply : R

override def toString : java.lang.String
Returns a string representation of the object.

The default representation is platform dependent.

Returns
a string representation of the object.