and pick up Scala.

Source: Internet
Author: User

Scala runs on top of the JVM, with a huge library of classes and tools, both functional and object-oriented.

In Scala, the interpreter is the repl we like, the type of a variable or function is always written behind a variable or function (as opposed to Java), and the conversion of a numeric type is done by means of a method rather than coercion of type, separated by semicolons only if there are multiple statements in the same line of code.

Scala allows custom operators to be used in a decent way, and you can omit the Scala prefix when using a package that starts with Scala. Scala does not have static methods, similar features can be used with singleton objects, a class corresponding to the companion object is the same as the static method in Java, the use of companion object application method is a common method of building objects in Scala.

Control

In Scala, the judgment statement is similar to other languages, but the {} block contains a series of expressions, and the result is an expression, and the value of the last expression in the block is the value of the block.

There is no Val or var designation before the variable for the For loop. The type of the variable is the element type of the collection, and the scope of the loop variable continues until the end of the loop. Scala does not provide a break or continue statement to exit the loop, as follows: 1) Use the Boolean control variable 2) with the nested function--return 3 in the function) using the break method in the Breaks object. The transfer of control is done by throwing and catching exceptions, and for performance reasons, try to avoid this mechanism.

For a rich pattern, you can provide multiple generators with an expression that starts with if, and you can use any number of loop variable definitions.

Function

Scala's methods manipulate objects, but functions are not, and C + + has functions, but in Java, the smart static method simulates, Scala's functions do not need return, the corresponding recursive function must indicate the return type, you can mix unnamed and named parameters, As long as those unnamed parameters are in front of the line.

Similarly, a variable-length parameter list is convenient by: _* Converts a sequence of values into a parameter sequence. When you change a Java method that has a parameter type of object, you need to convert the base type manually.

Scala has a special notation for functions that do not return a value, if the function body is enclosed in curly braces but there is no previous = number, then the return type is unit, and such a function is called a procedure function.

When Val is declared as lazy, its initialization is deferred until it is first evaluated. Each time you access a variable that is loaded lazily, a method is called to check whether the value has been initialized in a thread-safe manner.

Abnormal

Scala exceptions work like Java or C + +, but there is no "inspected" exception, the catch exception takes pattern-matching syntax, does not need to use the caught exception object, you can use _ to replace the variable name. Try/catch and try/finally are complementary.

and pick up Scala.

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.