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