Hi, I'd like to ask if type inference is considered an acceptable coding practice (when instantiating generic classes).
Normally, we would create new instances of generic classes as such:
List<Integer> newList = new ArrayList<Integer>(); // No type inference
However, we can use type inference here:
List<Integer> newList = new ArrayList<>(); // Type inference used
I can't seem to find any guidance regarding this (on both the provided style guide, as well as the Google style guide). I would appreciate some insight regarding this. Thanks!
PS: IntelliJ's linter seems to recommend using type inference. But I was also taught previously that we should try to avoid type inference when possible.
Hi, I'd like to ask if type inference is considered an acceptable coding practice (when instantiating generic classes).
Normally, we would create new instances of generic classes as such:
List<Integer> newList = new ArrayList<Integer>(); // No type inference
However, we can use type inference here:
List<Integer> newList = new ArrayList<>(); // Type inference used
I can't seem to find any guidance regarding this (on both the provided style guide, as well as the Google style guide). I would appreciate some insight regarding this. Thanks!
PS: IntelliJ's linter seems to recommend using type inference. But I was also taught previously that we should try to avoid type inference when possible.