Scala type inference and library method design principles and what is the difference between = = and Java

Source: Internet
Author: User

Scala type inference

Method Msortswapped (ABCD) (_>_)

Typically, once you have a task that needs to infer multiple method type parameters, the type inference only references all parameter types in the first argument list, but does not refer to other parameters after that. Because the method msortswapped is a method of curry, with two parameter lists, the second parameter (that is, the value of the function) will not be used as a reference for determining method parameters.

Therefore, this type inference scheme also implies the following library method design principles: If you need to design a parameter as a number of non-function values and a function value of some polymorphic method, you need to put the function parameters on the last side of the Curry parameter list. This way, the correct type of the method can be inferred from the non-function parameter class, and this type can be used instead to complete the function parameter type checking. This allows the user of the method to avoid providing more type information and to compile a more concise function literal.

What's the difference between = = and Java

Scala's = = follows the comparison rules:

First check whether the left side is null, if not, call the left manipulation data of the Equals method. Therefore, the exact comparison depends on the definition of the Equals method that makes the operation. Because of the automatic null check, there is no need to manually check it again.

java = = can compare primitive types or reference types. For primitive types, the equality of the = = Comparison values for Java is consistent with Scala. Two for reference types, Java = = compares the equality of reference types, which means that two variables are compared to the same object in the JVM heap. Scala also provides this mechanism, named EQ. However, EQ and its antonym neq are applied only to objects that can be mapped directly to Java.

Scala type inference and library method design principles and what is the difference between = = and Java

Related Article

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.