If scala methods belong to classes, how come can one create a method outside of a class?
As in:
def hello(a:String) {println(s"Hello $a")}
What class does this method belong to?
And why is there such a concept (method outside of class) at all? My first impression is that it generates a lot of confusion, since it is redundant (you can already have "normal" functions).
Actually if you put this code to file
Smth.scalaand try to compile it you'll see that it doesn'tI guess you wrote this code in repl. In repl every line is compiled in some object.
In Scala 3 top-level definitions will become possible
https://dotty.epfl.ch/docs/reference/dropped-features/package-objects.html