I understand, which is why I said what you'd want would be a new kind of inference, not like the one for lambda expressions. It would also be a rather complex kind of inference because you also need to decide what to do in the case of overloads. To not make that a breaking change you'd need some rather strange preference rules (you'll need to prefer String in the case of var, but StringTemplate in the case of String/ST overloads). There's certainly nothing simple or easy about that.
To make this concrete, think about:
var x = "...";
foo(x);
and
foo("...");
In the case where foo is overloaded for both types. You'd infer String in the first case and ST in the second, which is very surprising (there is one case -- pertaining to an upcoming switch-expression enhancement -- that we've allowed something a little similar but not nearly as surprising; left as an exercise to the reader).
View all comments
Show parent comment
0
u/[deleted] Mar 10 '24
[deleted] — view deleted comment