Im relatively new to scala functions and I'm getting confused on how this syntax sugar actually works and when to use a particular type.
I have written 3 functions all which should do the same thing, but I'm having problems understanding why Function0 is behaving differently
version 1
val fn1 : (String) => String = System.getProperty(_)
println(fn1("os.name"));
version 2
val fn2 : () => String = System.getProperty("os.name")
println(fn2());
Version 2 gives type mismatch; found : String required: () ⇒ String
version 3
val fn3 = () => System.getProperty("os.name")
println(fn3());
I understand that for version 2 scala already knows the return type of System.getProperty but why does it produce that particular error, why does it prevent me form explicitly stating the return type. I personally prefer explicit return types so I don't have to dive into a method to see what it is returning.