© Kishori Sharan 2019
K. SharanJava 13 Revealedhttps://doi.org/10.1007/978-1-4842-5407-3_1

1. Local Variable Type Inference

Kishori Sharan1 
(1)
Montgomery, AL, USA
 
In this chapter, you will learn
  • What type inference is

  • What local variable type inference is

  • What the restricted type name var is

  • The rules to use var to declare local variables, indexes of for-each loop and for loop, and formal parameters for implicitly typed lambda expressions

What Is Type Inference?

Suppose you want to store a person ID, say, 10, in a variable. You would declare the variable like
int personId = 10;
To store a list of person IDs, you would declare a variable like
ArrayList<Integer> personIdList = new ArrayList<Integer>();
How about rewriting these variable declarations ...

Get Java 13 Revealed: For Early Adoption and Migration now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.