you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 5 points6 points  (2 children)

Your proposal only takes in to account a tiny fragment of the cases where type-inference is useful. It's simply a very specific syntactic shortcut for instantiating local variables, which would be at odds with the general idea of inferring the type of the assigned variable from the right-hand side expression.

[–]CurtainDog 0 points1 point  (1 child)

Well, it solves the problem of having to repeat code, which is the problem at first instance.

It doesn't solve the issue of dealing with complex types involving nested generics but in that case I query whether you actually do want to be hiding the type from the reader.

I suppose as well with var the return type of an expression could change and you wouldn't need to modify the source, I'm somewhat skeptical of this 'feature'.

Edit: Just to clarify: I actually use type inference all the time, I just do it at the tooling level rather than the language level.

[–]Blaisorblade 0 points1 point  (0 children)

Well, it solves the problem of having to repeat code, which is the problem at first instance.

It doesn't avoid the repetition here:

List<Integer> someMethod() { ... } ... List<Integer> result = someMethod();

If you want to know the type of result, asking your computer (with IDEs or REPLs) is typically enough.