Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 533
Edmondo1984 Avatar asked Jun 09 '15 19:06

Edmondo1984


1 Answers

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.

like image 70
Akos Krivachy Avatar answered Sep 19 '22 22:09

Akos Krivachy