Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
21 lines (15 loc) · 687 Bytes

File metadata and controls

21 lines (15 loc) · 687 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// A simple demonstration of local variable type inference.
public class VarDemo {
public static void main(String[] args) {
// Use type inference to determine the type of the variable named avg. In this case, double is inferred.
var avg = 10.0;
System.out.println("Value of avg: " + avg);
// In the following context, var is not a pre-defined identifier. It is simply a user-defined variable name.
int var = 1;
System.out.println("Value of var: " + var);
// Interestingly, in the following sequence, var is used as both the type of the declaration
// and as a variable name in the initializer.
var k = -var;
System.out.println("Value of k: " + k);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.