Java 10 var: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 9: Line 9:
=var and Code Readability=
=var and Code Readability=


Type inference reduces the amount of time it takes to write Java code, but it does not necessarily improve its readability. Some say that developers spend much more time reading source coding than writing it, so probably the amount of time it takes to write the code should be optimized in favor of readability.
Type inference reduces the amount of time it takes to write Java code, but in some cases does not necessarily improve its readability. Some say that developers spend much more time reading source coding than writing it, so probably the amount of time it takes to write the code should be optimized in favor of readability. However, there may be cases when var actually improves readability by eliminating obviously redundant type declaration in a very local context. Logically, this is similar to naming a variable "i" instead of "internalProcessId" in a short loop.

Revision as of 16:02, 25 May 2018

Internal

Overview

The feature behind the Java 10 new keyword var is called local variable type inference.

var and Code Readability

Type inference reduces the amount of time it takes to write Java code, but in some cases does not necessarily improve its readability. Some say that developers spend much more time reading source coding than writing it, so probably the amount of time it takes to write the code should be optimized in favor of readability. However, there may be cases when var actually improves readability by eliminating obviously redundant type declaration in a very local context. Logically, this is similar to naming a variable "i" instead of "internalProcessId" in a short loop.