⬆️ ⬇️

Java "var" keyword: please, not this

Var keyword



The past March 8th for Java developers was particularly intense. The reason for this was the new JEP 286: Local-Variable Type Inference , which suggests entering the var keyword, eliminating the need to explicitly specify the type of a local variable:



var unbufOut = NetUtils.getOutputStream(sock);






OutputStream unbufOut = NetUtils.getOutputStream(sock);


, — var Java . ?



, ( ) :



No god please no



, JEP .



«»



Java . . Unsafe, API, — .



, , Java . -, . , . -, . , , Scala C#, . , type inference return, . Java .



var — . «» : , , . ( — ) var, . , , .





, . , , -IDE. - . IDE - . , , IDE , .



:

Scope is small, so will only give more confussion to new developers. The typing of the boiler plate is tackled by decent IDEs.
We have IDEs so I don't care


type inference .



« ». , , IDE, «notepad» — , , «Hello, world!». . IDE — . : , mail-, -, , . JIRA- , , ? — , . , var .



I'm not sure if it will not increase the difficulty of code review
I code both in Java and C# and sometimes and need to work with C# code where people have used var. It makes it a lot harder to see the type of a variable for no or very little gain.


«»



— . , . — . .



. . . , - Gang Of Four, . . , , , .



. . - , , . , . , , .



var, , . , type inference — C++, C#, Scala… — ? , - type inference. - , - , - , - , .



Akk Spark. , - type inference. — . . , . . .





, , Java. , . — , J2EE , , . Java .



, JVM-based . , Akka Spark Scala? — Java-. ? , , , var, , Java. .



Thanks so much! This will remove yet another death-by-a-thousand-cuts issues w Java that drive people to seek alternatives
Please simplifiy the Java language (and JavaEE in general)! Type inference is a great step into the right direction.




: «» . , . . , :

Is there way to add union and intersection types in Java?
Could you consider the introduction of case classes (like in Scala)?
when do you expect primitive types be allowed in generics?
Remove getters and setters.
When will we have async/await feature in Java ( like c# and f# ) ?


var . .


')

Source: https://habr.com/ru/post/280075/



All Articles