----- Mail original -----
> De: "Jochen Theodorou" <[email protected]>
> À: "dev" <[email protected]>
> Envoyé: Samedi 8 Septembre 2018 14:22:25
> Objet: Re: About type inference of method return value

[...]
> 
> "var" is a bit a different story. It will lead to surprising types being
> used and partially violates the paradigm that you should not use the
> most special class for your variables if not needed. But even then the
> effect is quite local. If you keep your methods small, as you should
> anyway, then there is not much of a disadvantage here to be seen in my
> opinion. But it already makes the program less readable for another
> user. It is the same in dynamic Groovy with def... Which shows you
> simply have to learn to read the method differently. But the effect is
> very localized.

yes, using an interface instead of a concrete type is only useful if the type 
is visible from the outside, so parameter types/return type of public methods 
or public fields should use interfaces. A local variable (or a private field) 
is never visible from another class so one should use a concrete type here, 
there is not point to ask the VM to de-virtualize when it's not necessary (even 
if de-virtualisation is cheap).   

> 
> Now return type inference is not, as I have shown already. And that,
> plus the lazy developer part, is why I am not friend of this.
> 
> bye Jochen

Rémi

Reply via email to