JEP 286: Local-Variable Type Inference
I hope this goes through!<p>A while back, I was trying to explain in what ways Scala is more typesafe than Java for a friend (which was one argument to why I prefer Scala so much), and ended up realizing how important type inference is in this regard.<p>The reason was this:
quite often type signatures correctly modelling a domain ends up being pretty hard to read. In a good and proper API, this happens in particular whenever something is composable and is, in fact, composed (if one can say that). I suppose one can say that, for Scala, it took a bit of time before people figured out how to do this properly, rather than just hacking the type system, but I feel that the ecosystem is more or less there now... YMMV though...<p>As an example: in something like Slick (a functional-relational mapper) in Scala you end up with monads to model your SQL query. One advantage this has is compile errors whenever you&#x27;re doing something wrong (i.e. more typesafe), but the types that a SQL query representation ends up with will necessarily be pretty hard to read and practically impossible to write (you could have a Query of a long chain of other types for example if you&#x27;re querying multiple columns).
In this example, somebody writing the query might not care about the type of the query. They will care about what the query will end up returning when executed though. I suppose it will lead to trouble when you can&#x27;t read the type signatures well enough and try to figure out the compiler error, but I reckon it&#x27;s better to have an error, than to see it fail runtime (at least in my world :). It&#x27;s easier and safer to do maintenance too, since the compiler and IDEs can know how things should work.<p>In any case, you could conclude that, in a statically compiled language where you do not have type inference, you&#x27;ll end up trading in preciseness in the model of the domain, in order to have readable code from the callsite. In turn, this leads to less typesafe code.<p>One challenge that Java will have even when implementing this though, is how to move the entire ecosystem to something that is indeed more typesafe. This only works if the APIs are doing this right.<p>EDIT: typos, language and less parens