Programming in Scala Reading Note 4

Source: Internet
Author: User
Basic Types and operations

Something new according to Java

 

1 + 2 is the same as (1). + (2.

Val STR = "Hello World"

STR indexof 'O' is the same as Str. indexof ('O ')

Indexof has two forms of parameters: int and STR, where the int is used to determine whether there isChar....

 

Any method can be an operator

This sentence should be understood as follows: indexof in Str. indexof ('O') should be called method, while indexof in STR indexof 'O' is an operator, just like + ....

 

Unary operator

  1. Prefix: the method of The unary operator is defined as follows:Unary _(M), where M can only be + ,-,!,~ One
  2. Suffix: that is, the method without parameters. Here is an agreement,If a method has no side effects, this method can omit (), for example, the string tolowercase method. If there are side effects, this () cannot be omitted, for example, println ()
    •   THe convention is that you include parentheses if the method has side effects, such as println (), but you can leave them off if the method has no side effects, such as tolowercase invoked on a string

Str. tolowercase ()

Str. tolowercase

STR tolowercase ()

STR tolowercase

They are all the same ....

A problem. I don't know why they can't put it together.

 

=

Scala = is different from Java =

When the = in Java is used for the primitive type, the value is compared. The Scala method is the same as that in Java.

1 = 1; true = false; and so on

In Java, = is used to compare the equality of the reference type, specifies whether to point to the same object (the two variables point to the same object on the JVM's heap ).

OK something wait for prepair

Val set1 = scala. collection. Immutable. Set (1, 2, 3)

Val set2 = scala. collection. mutable. Set (1, 2, 3)

Set1 = set2 // true !!!

 

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.