3 ms·
Agreed, but: Animal customer = new Cat(); It makes it clear how the new object will be used. It does come up quite frequently, especially with Collection an
by RyanZAG 11y ago
Agreed, but:
Animal customer = new Cat();
It makes it clear how the new object will be used. It does come up quite frequently, especially with Collection and List. Nobody was saying it is not verbose and can lead to boilerplate. The assertion is that when viewing a large code base, you are always sure of the type of value you are dealing with on a local level. If all of your objects are well defined, you don't even need to look at how the class is created (a billion getters and setters? irrelevant to the local function) as you only need to deal with the local function.
- lmm 11y agoThat's there if you want it though. val customer = new Cat(): Animal I can see arguments against inter-method type inference, but I think there's no real argument against type inference within a single method (requiring explicit types on method boundaries). If you have a billion-line method you have bigger problems.