Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Scala starts from an object's main method instead of a class's static main method?

In Java, a program starts from a class's static main method. But in Scala, it starts from a object's main method.

Does anyone know the rationality of designing like this?

Scala also provide a trait called App, which can replace main method if an object extends this trait. Does anyone have ideas about which one (App or main) is the preferred way?

Thanks!

like image 910
Hanfei Sun Avatar asked Dec 06 '22 23:12

Hanfei Sun


1 Answers

Scala has singleton objects instead of java static members. So main method of object is analogue of java static main method.

like image 184
Sergii Lagutin Avatar answered Jan 18 '23 22:01

Sergii Lagutin