Java 10 – Local Variable type inference – ‘var’ type

What is it?

  • New way of declaring local variable – ‘var’
  • Variable with ‘var’ type can be declared. Using this, the type of the variable is inferred from the context
  • Only allowed for method local variables

Example:

Output:

References:

https://docs.oracle.com/javase/10/language/toc.htm#JSLAN-GUID-7D5FDD65-ACE4-4B3C-80F4-CC01CBD211A4

 

Leave a Reply

Your email address will not be published. Required fields are marked *