Generate return type signature in Scala with Intellij Idea

2.6k Views Asked by At

While Scala has a type inference, it is considered good practice to explicitly define the return type of public functions. Is it possible to get IDEA add the explicit return type from the inferred one?

1

There are 1 best solutions below

2
On BEST ANSWER

If you are on a method name then you can hit ALT + ENTER to get the Intention Actions where the first is usually the Add type annotation to function definition

Illustration:

Pressing Alt+Enter on a method

In this case it would add Int to the return type of the exampleFunction.

Might I add this also works for val/var declarations, essentially whenever there is a type inferred.