I’m attempting to learn Scala coming from a Java background. Should the below program run ? When I right click on the file Functional an option to run the file is not displayed. What do I need to change to run the method Timer.run?
I’m using the Eclipse3.7 & Scala plugin 2.0.2.
class Functional {
object Timer {
def oncePerSecond(callback: () => Unit) {
while (true) { callback(); Thread sleep 1000 }
}
def timeFlies() {
println("time flies like an arrow...")
}
def run() {
oncePerSecond(timeFlies)
}
}
def main(args: Array[String]) {
Timer.run();
}
}
The main method should reside on an
objectdefinition, not inclass. The methods that are defined in anobjectare somewhat equivalent tostaticones from Java.