From bf1d9d46d08f2c835d342142b31a1ce32550d31c Mon Sep 17 00:00:00 2001 From: Matthias Zenger Date: Mon, 12 Jan 2004 15:44:30 +0000 Subject: Formerly known as class Executable. --- sources/scala/Application.scala | 51 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 sources/scala/Application.scala diff --git a/sources/scala/Application.scala b/sources/scala/Application.scala new file mode 100644 index 0000000000..bb289ed79d --- /dev/null +++ b/sources/scala/Application.scala @@ -0,0 +1,51 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2002, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +** $Id$ +\* */ + +package scala; + + +/** The Application class can be used to quickly turn objects + * into executable programs. Here is an example: + *
+ *  object Main with Application {
+ *    Console.println("Hello World!");
+ *  }
+ *  
+ * Here, object Main inherits the main method + * of Application. The body of the Main object + * defines the main program. This technique does not work if the main + * program depends on command-line arguments (which are not accessible + * with the technique presented here). + * + * It is possible to time the execution of objects that inherit from + * class Application by setting the global scala.time property. + * Here is an example for benchmarking object Main: + *
+ *  java -Dscala.time Main
+ *  
+ * + * @author Matthias Zenger + * @version 1.0, 10/09/03 + */ + +class Application { + + /** The time when execution of this program started. + */ + val executionStart: Long = java.lang.System.currentTimeMillis(); + + /** The default main method. + */ + def main(args: Array[String]) = { + if (java.lang.System.getProperty("scala.time") != null) + java.lang.System.out.println("[total " + + (java.lang.System.currentTimeMillis() + - executionStart) + "ms]"); + } +} -- cgit v1.2.3