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 - Java Tutorial
From the course: Nail Your Java Interview
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Understand the impact of Jigsaw2m 40s
-
(Locked)
Use optionals to avoid NullPointerExceptions3m 26s
-
(Locked)
Create Lambdas to pass functionality as data5m 14s
-
(Locked)
Use the Streams API to process collections3m 57s
-
(Locked)
Discuss the pros and cons of local variable type inference2m 42s
-
(Locked)
Leverage new switch expressions3m 36s
-
-
-
-
-
-