Generate return type signature in Scala using Intellij Idea

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

+3


source to share


1 answer


If you are using the name of the method, you can hit ALT+ ENTERto get Intention actions, in which the first is usuallyAdd type annotation to function definition

Illustration:

Pressing Alt + Enter on a method



In this case, it will add Int

to the return type exampleFunction

.

May I add this, also works for declarations val

/ var

, essentially whenever there is a type that is inferred.

+10


source







All Articles