4 ms·
Is there an automatic refactoring that changes type-inferred variable declarations and changes then into typed declarations? I can see the value when writing c
by tareqak 4y ago
Is there an automatic refactoring that changes type-inferred variable declarations and changes then into typed declarations?
I can see the value when writing code in the early stages of a project to both have flexibility and save keystrokes with type inference to help prototype and explore the problem space. Later on, I can see the benefit of switching to typed variable declarations for readability as time goes on and that part of the code base slips away from my working memory.
- valenterry 4y agoYes, there is. That's one of the great things about Scala's typesystem. It makes those things easy to even write yourself, but there is already something builtin: https://scalacenter.github.io/scalafix/docs/rules/ExplicitResultTypes.html https://scalacenter.github.io/scalafix/docs/rules/ExplicitRe... However, from my experience it's actually better to not annotate most things. I annotate methods are that used very often or are "borders" of my API or interface. Otherwise it is usually not needed because it rarely makes the code more clear and IDEs like IntelliJ actually show you the types inline automatically, so you can always see the return type easily.