Original Scala Learning: About variables (Val,var, type inference)

Source: Internet
Author: User
Tags constant definition

1. Constant definition: Val

Val is similar to the final variable in Java. Once initialized, Val can no longer be assigned a value
Val megs = "Hello World"

2. Definition of variable: var

var is like a non-final variable in Java that can be assigned multiple times within its declaration period
var spark:string = "I am Big Data"
var spark:string = "I Am"

Table key additions and hints are supported in the interpreter

3. Variable type inference:

When assigning an initial value to a variable, the Scala compiler can calculate the variable type based on the value assigned to it. This is known as variable type inference. Therefore, the declaration of these variables can be written as follows:

var=ten;  ="Hello, scala!" ;

here, by default, MyVar is of type int and will be set to Myval as a string variable .

Original Scala Learning: About variables (Val,var, type inference)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.