From the course: Nail Your Java Interview

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Discuss the pros and cons of local variable type inference

Discuss the pros and cons of local variable type inference - Java Tutorial

From the course: Nail Your Java Interview

Start my 1-month free trial

Discuss the pros and cons of local variable type inference

- [Instructor] Introduced in Java 10, local variable type inference can help collapse some long class names in initializing variables in your code. Local variable type inference means that you'll be able to initialize variables without having to specify the associated type. Let's take a look. In initializing variables, usually we have the data type, the variable name, and the value we want to initialize the variable with. With local type inference, we can replace the data type at the front with the identifier VAR. So we'll take away the list, write VAR, we'll take away double, write VAR. This new syntax reduces the verbosity associated with writing Java code. It's called local variable type inference because we infer the type from the context. For example, when we say VAR total equals 38.23, the compiler will already know the type is double. With this, Java still remains a statically typed language. Once the type is…

Contents