Edmondo
Edmondo

Reputation: 20080

Generate return type signature in Scala with Intellij Idea

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?

Upvotes: 7

Views: 2666

Answers (1)

Akos Krivachy
Akos Krivachy

Reputation: 4966

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.

Upvotes: 15

Related Questions