News for hackers. Stuff that matters.
Re:JDK 10: General Availability by merb on Wednesday March 21, 2018 @05:44AM (#16636646)
var is inside jdk10... http://openjdk.java.net/jeps/286
Re:JDK 10: General Availability by ygra on Wednesday March 21, 2018 @05:56AM (#16636692)
I think they meant the separate keywords to distinguish "var" and "final var". Personally I like just reusing the final keyword, which for once would actually mean the very same thing in the very same place, with "var" just taking place of the type name. More familiarity, less surprises.
Re:JDK 10: General Availability by trzmiel4 on Wednesday March 21, 2018 @05:55AM (#16636684)
The problem is that "val" or "const" is not.
Re:JDK 10: General Availability by koolba on Wednesday March 21, 2018 @06:30AM (#16636806)
Besides the 6 extra chars, the difference between “final var foo = ...” and “val foo = ...”?
Re:JDK 10: General Availability by Hasknewbie on Wednesday March 21, 2018 @07:48AM (#16637177)
I would argue it's not about the extra characters, it's about enforcing explicit mutability.

In Scala, where var/val both exist, each time you declare a variable you are forced to think about its mutability. But if you only have "var", with the _option_ of tacking "final" to it, then a programmer can simply forget to make that decision, because the language allowed them to.

Re:JDK 10: General Availability by trzmiel4 on Wednesday March 21, 2018 @06:34AM (#16636830)
Those "6 extra chars" mean more noise for human on the screen, it can lead to line wrapping or in other way harm the formatting, and last but not least it does not make it easier to promote good coding practices.
Re:JDK 10: General Availability by ygra on Wednesday March 21, 2018 @07:03AM (#16636975)
If the final keyword hadn't existed before I'd agree, but it does exist, does exactly what you'd expect it to here, and I'd argue that since it's consistent with how it used to work, is actually easier to understand and grasp. Local type inference is a new feature. Locals that can be assigned once is not and people are already familiar with how such locals are declared. And there's no ambiguity which variant is the correct one, e.g.:

    var i = 0;
    final var i = 0;
    int i = 0;
    final int i = 0;
    val i = 0;
One of the options there is a very odd one. And if there was "val", would "final var" be disallowed?
Re:JDK 10: General Availability by charriu on Wednesday March 21, 2018 @06:55AM (#16636936)
None of course, but I think that's the point of the complaint. For a feature supposed to increase convenience, it didn't go as far as it could have. Still, I'm glad var is in there. (Now, my employer just needs to get off of Java 8...)
Re:JDK 10: General Availability by merb on Wednesday March 21, 2018 @07:42AM (#16637142)
be carful with adopting java9 and java10. they won't live that long...
Re:JDK 10: General Availability by chrislynch42 on Wednesday March 21, 2018 @07:35AM (#16637114)
var seems like a bad idea to me. One of the things I like about Java is (strong?) typing. Recently learning C# and was put off by 'var'. Why is it a good idea?
Re:JDK 10: General Availability by ceronman on Wednesday March 21, 2018 @07:46AM (#16637164)
'var' in C# and Java doesn't change strong or static typing at all. It's just type inference. Your code is still statically typed, the compiler and IDE will catch errors. It's just that it's smart enough to infer the types of redundant things instead of making you type it.

So instead of typing:

  AbstractConcreteFactoryFactory factory = new AbstractConcreteFactoryFactory();
You can just type it only once:

  var factory = new AbstractConcreteFactoryFactory();
Re:JDK 10: General Availability by bpicolo on Wednesday March 21, 2018 @09:47AM (#16637915)
It drastically decreases mental/physical overhead of typing the dang code out without in any way affecting typing.

C# is a huge breath of fresh air compared to java largely because of useful type inference. It's easy to make compilers do more work now.

Rust is doing type inference with drastically stronger types, for example.

Re:JDK 10: General Availability by pjmlp on Wednesday March 21, 2018 @07:47AM (#16637171)
Variables declared with var are still strongly typed. Just because the keyword exists in JavaScript, it doesn't mean it has the same semantic meaning.

    var p = new Person();
    
    p = 1234; // This will trigger a compile time error
Re:JDK 10: General Availability by merb on Wednesday March 21, 2018 @07:40AM (#16637134)
depends, writing something like:

`Simple<List<Map<String, Demo>, OtherList<Map<Int, String>>` is a little bit painful.

I use scala and basically most often at least public Methods should (in scala you can omit even that, however some functional libraries need a return type) have a explicit type, which most often is enough.