© 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 as follows? ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.