I know you can create an anonymous function, and have the compiler infer its return type:
val x = () => { System.currentTimeMillis }
Just for static typing's sake, is it possible to specify its return type as well? I think it would make things a lot clearer.
Fabian gave the straightforward way, but some other ways if you like micromanaging sugar include:
or
or even
since in most situations it makes no difference if it descends from Function, only whether it has an apply.
In my opinion if you're trying to make things more clear it is better to document the expectation on the identifier x by adding a type annotation there rather than the result of the function.
Then the compiler will ensure that the function on the right hand side meets that expectation.