UntypedVariables
DRAFT

Misconception:

You can declare a variable without specifying its type (e.g., var x).

Incorrect

Variable declarations don't need a type

Correct

Variable declarations need a type

Correction
Here is what's right.

Before Java 10, every variable declaration (local variables, formal parameters, instance variables, and class variables) had to explicitly specify the type of that variable.

Starting with Java 10, local variable declarations do not need to specify the type anymore (they can use var name = ...;).

However, it is important to understand that Java is statically typed, and all its variables have to be declared, and their type has to be determined statically (at compile time).

In Java 10, var was added to declare local variables without having to explicitly specify their type, allowing developers to rely on the Java compiler to (statically) infer the type of local variables.

Stay up-to-date

Follow us on  twitter to hear about new misconceptions.