I'm migrating some pre Java 10 code and I'm wondering if IntelliJ offers a way to automatically refactor the code to replace the variable declarations that uses the actual type with var wherever it's possible.
The code is full of stuff like:
String status = "empty";
BigDecimal interest = BigDecimal.ZERO;
List<Future<Boolean>> results = es.invokeAll(tasks);
LocalDate start = LocalDate.of(2020, 1, 1);
And I would prefer:
var status = "empty";
var interest = BigDecimal.ZERO;
var results = es.invokeAll(tasks);
var start = LocalDate.of(2020, 1, 1);
I already looked in IntelliJ's settings (Code Style/Inspections) and couldn't find anything.
var
everywhere, though? I think it often depends whether you should use it, e.g.MyComplexType bla = create()
gives me more information thanvar bla = create()
. The thing about old code is that you read it much more often and don't want to guess the types in such cases. So there is no good way to know whether to usevar
or not, and no way to automate these choices.