About java var

Java variable declaration var

This is a memo for organizing Java Silver study ...

How to use var

--Appeared from SE10 --Type inference of local variables --Data type is inferred according to the value on the right side

var v1 = "hoge";  //Treated as a String
var v2 = 123;     //Treated as an int

--Because it is variable type inference, ** declaration only ** cannot be done-> because type inference cannot be done without assigning a value --Therefore, ** null assignment is not possible **

var v3;           //This is a compile error
var v4 = "huga";  //ok
var v5 = null;    //This is also a compile error

--Cannot declare multiple variables

int i1 = 1, i2 = 2, i3 = 3;  //ok
var v6 = 6, v7 = 7, v8 = 8;  //Compile error

--Cannot be used as a method formal argument type

String piyo(var val){
//Compile error

Recommended Posts

About java var
About Java interface
[Java] About Java 12 features
[Java] About arrays
Where about java
About Java features
About Java threads
[Java] About interface
About Java class
About Java arrays
About java inheritance
About interface, java interface
About List [Java]
About Java literals
About Java commands
About Java log output
About Java functional interface
Java, about 2D arrays
About class division (Java)
About [Java] [StreamAPI] allMatch ()
About Java StringBuilder class
[Java] About Singleton Class
About Java method binding
[Java] About anonymous classes
About method splitting (Java)
[Java Silver] About initialization
About Java Array List
About Java Polymorphism super ()
About inheritance (Java Silver)
About Java String class
About Java access modifiers
About Java entry points
About Java 10 Docker support
Personal summary about Java
[Java] About enum type
All about Java programming
About java abstract class
A note about Java GC
What I researched about Java 8
About an instance of java
[Gradle] About Java plug-in tasks
About Java variable declaration statements
[Java] About try-catch exception handling
About Java class loader types
[Java] About String and StringBuilder
What I researched about Java 7
About =
About Alibaba Java Coding Guidelines
About Java Packages and imports
About abstract classes in java
[Android / Java] Learned about DataBinding
What I researched about Java 5
How about TECH ACADEMY ?? [Java course]
[Introduction to Java] About lambda expressions
About fastqc of Biocontainers and Java
About Lambda, Stream, LocalDate of Java8
Learn about transaction savepoints (with Java)
[Java beginner] About abstraction and interface
About signature authentication with java 1st