Scala main

Amainis the method that is being called to start your program. It needs a specific structure – calledprototypewhen talking about methods – to be recognized.

Until now we ran all the SKBs inWorksheetmode which hides themainfrom us.

If you have tried to remove or change themainfunction, you might have noticed an exception:

java.lang.RuntimeException: No main class detected.

ThisExceptionwill be thrown if amainmethod cannot be found or is not contained within anobject. Try to change the code to trigger it.

The main prototype is always of the form:

def main(args: Array[String]): Unit = 
Theargs: Array[String]is where you would be able to read and use the arguments given to the application when started.

That is pretty much it concerningmain, so I thought it would be nice to combine some of the things we've seen in the past. This SKB is usingMap,object,Option,lazy val,defall into the same project. Try to play with it and make it your own.

Reveal more information and clues
Load Exercise