Reputation: 81
I wrote the below scala code in my IDE(IntelliJ) to create an anonymous function :
val hi = () => "Hi"
When I desugar my scala code , IDE gives me code like one below :
val hi: Function1[(), _root_.java.lang.String] = () => "Hi"
But it is giving error : '=>' expected but ',' found.
Upvotes: 0
Views: 65
Reputation: 15295
As said by Luis, hi
is a function of no input parameter that produces a String
, thus its type is Function0[String]
.
If it was defined like this for instance it would be a Function1[String, String]
:
val hi1 = (name: String) => s"Hi $name"
Upvotes: 1