JEP 286: Local-Variable Type Inference: Usage
tbee at tbee.org
Fri Mar 30 05:36:31 UTC 2018
It is very comforting to see restraint when new features become available. IMHO a lot of the var-readability comes down to moving the type information into the variable name (which I personally do already anyhow) and regionality.
On 29-3-2018 20:41, Kevin Rushforth wrote:
> I tend to agree, so I would prefer to see them used judiciously. The write-up by Stuart (referenced below) raised some good points about when to use them vs when you might not want to.
> -- Kevin
> Artem Ananiev wrote:
>> On 2018/03/29 9:36, Kevin Rushforth wrote:
>>> As a prerequisite, we would need to update the minimum boot JDK to JDK
>>> 10, which I was going to propose doing anyway -- it seems the right time
>>> now that JDK 10 is out.
>>> I have no objections to then allowing the use of 'var' in new code.
>>> Do any others have any concerns?
>> My personal experience with "var"s - they are used a lot in Scala, for example - is they make code very unreadable, especially when working with collections and streams. The only case when a "var" is suitable is new object creation:
>> var object = new SomeType()
>> In all other cases they are more painful than valuable.
>> I can say it differently. It's very easy to use "var"s wrong. No matter what style guides are available, people will often use them in a way that makes code less readable.
>> Just my $0.02
>>> -- Kevin
>>> Nir Lisker wrote:
>>>> A style guide for usage of 'var' has been published at
>>>> http://openjdk.java.net/projects/amber/LVTIstyle.html. Can we start using
>>>> this feature in contributions to OpenJFX?
>>>> - Nir
More information about the openjfx-dev