In their list of risks there's one missing: it makes changing the return type of a method to a subclass a subtly breaking change. Say some api defines a method, Collection getNames() { ... } and in your code you do var names = getNames(); if (...) names = Collections.emptySet(); Now, if the api later changes getNames() to be List getNames() { ... } your code breaks. That's one of the advantages of only allowing this…
JEP 286: Local-Variable Type Inference
91–100 of 132 posts
Re: JEP 286: Local-Variable Type Inference
#92The reaction here is indicative of why I'm starting to consider whether maybe it's best that Java stays Java. Sure, I'd personally be really annoyed typing super redundant type declarations everywhere. But then again, I wouldn't have to, because I'd simply use Scala, because it's more expressive. But a lot of people clearly love good old verbose Java. Java has been super slow to adopt things that are more or less the…
Re: JEP 286: Local-Variable Type Inference
#93This survey will remain open for one week, from Mar 9 to Mar 16.
Re: JEP 286: Local-Variable Type Inference
#94I've never liked this language feature very much. I'm the one that's doing the inference when I read the code.
For easy cases reading such code is OK (var path = "/usr/bin/whatever" - obvious), but with a more complex code it becomes awful.
I'm a C++ programmer, and quite often I have to dig through dozens of headers to find out what this magic "auto" really means.
Re: JEP 286: Local-Variable Type Inference
#95I hope they will give it second though. In Java 'var' or 'val' are not reserved keywords. It was difficult to migrate existing code when 'enum' was introduced. 'const' is reserved but nothing for variable, perhaps 'new' or some symbols.
Re: JEP 286: Local-Variable Type Inference
#96Earlier quoted context omitted.
Optional, alright, but promoting bad practices. If people like dumb-down languages, there are plenty of them already!
What are the bad practices being promoted by this? How does it qualify as dumbed down? Simply ranting about things that, charitably, you don't seem to understand, does not make the rants valid.
Re: JEP 286: Local-Variable Type Inference
#97Re: JEP 286: Local-Variable Type Inference
#98Earlier quoted context omitted.
My experience is similar, however more like: Groovy === happy developers
Same here. Groovy rocks my world and is the main reason I've barely even looked at Java 8.
Re: JEP 286: Local-Variable Type Inference
#99I expect this breaking a few things in fields injection (a la Spring @Autowired[1]) if implemented. [1] https://docs.spring.io/spring-framework/docs/current/spring-...
How would type inference for local variables mess with fields?
@Autowired is fundamentally about type-driven injection
If you replace:
@Autowired
FooDao fooDao;
with something like: @Autowired
var fooDao;
I'm pretty sure type-driven injection breaks.[1] https://docs.spring.io/spring/docs/current/spring-framework-...
Re: JEP 286: Local-Variable Type Inference
#100I've never liked this language feature very much. I'm the one that's doing the inference when I read the code.
I totally agree, type inference speed writing a code, nothing more. For easy cases reading such code is OK (var path = "/usr/bin/whatever" - obvious), but with a more complex code it becomes awful. I'm a C++ programmer, and quite often I have to dig through dozens of headers to find out what this magic "auto" really means.