Local Variable Type Inference (introduced in Java 10)
Local variable type inference enables you to declare variables without explicitly specifying their types. Instead, the compiler infers the type based on the assigned value. Here's an example:
var message = "Hello, World!"; // inferred as String
var numbers = List.of(1, 2, 3, 4, 5); // inferred as List<Integer>
No comments:
Post a Comment