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
- Prefix: the method of The unary operator is defined as follows:Unary _(M), where M can only be + ,-,!,~ One
- 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 !!!