() => Unit means: "A type function that takes no parameters and returns nothing"
So, if you declare the value of f function that takes no parameters and returns nothing, its type would be as follows:
val f : () => Unit
Since this is val , you need to assign a value like function that prints Hola mundo
val f : () => Unit = () => println("Hola Mundo")
It reads: * "f is a function that takes no parameters and returns nothing initialized with println("Hola Mundo") code println("Hola Mundo")
Since in Scala you can use type inference that you do not need to declare so that the following is equivalent:
val f = () => println("Hola Mundo")
To call it, you can simply:
f() >"Hola mundo"
Or, since functions are also objects, you can call the apply method:
f.apply() > "Hola Mundo"
That's why in your declaration you say: "I will have a list that will contain functions without parameters and return types", therefore List [() => Unit]
Hope this helps.
OscarRyz Aug 05 2018-11-11T00: 00Z
source share