0
# Type Inference
1
2
Local variable type inference for cleaner, more readable code with automatic type detection.
3
4
## Capabilities
5
6
### val - Final Local Variables
7
8
```java { .api }
9
public final class val {
10
private val() {}
11
}
12
```
13
14
### var - Mutable Local Variables
15
16
```java { .api }
17
public final class var {
18
private var() {}
19
}
20
```
21
22
**Usage Examples:**
23
24
```java
25
import lombok.val;
26
import lombok.var;
27
28
public class Example {
29
public void demonstrateTypeInference() {
30
val name = "John Doe"; // final String name = "John Doe";
31
val age = 30; // final int age = 30;
32
val users = new ArrayList<User>(); // final ArrayList<User> users = ...
33
34
var counter = 0; // int counter = 0;
35
var message = "Hello"; // String message = "Hello";
36
37
counter++; // OK - var is mutable
38
// name = "Jane"; // Compilation error - val is final
39
}
40
}
41
```