Zmienna Java
//this are the most common ones
int x = 5;
String y = "hello";
System.out.println(x + y);
Alexperto
//this are the most common ones
int x = 5;
String y = "hello";
System.out.println(x + y);
The var keyword was introduced in Java 10.
Type inference is used in var keyword in which it detects automatically
the datatype of a variable based on the surrounding context.
The below examples explain where var is used and also where you can’t use it.
// Java program to explain that
// var can used to declare any datatype
class Demo1 {
public static void main(String[] args)
{
// int
var x = 100;
// double
var y = 1.90;
// char
var z = 'a';
// string
var p = "tanu";
// boolean
var q = false;
// type inference is used in var keyword in which it
// automatically detects the datatype of a variable
System.out.println(x);
System.out.println(y);
System.out.println(z);
System.out.println(p);
System.out.println(q);
}
}
improve the readability of code for other developers who read the code.
In some situations