📜 ⬆️ ⬇️

Scala 2.10 release

Today, finally, the final version of Scala 2.10.0 has been released, which is reported on the official website.

New opportunities:


Value classes


Now custom classes can be inherited from AnyVal (previously it was possible only from AnyRef). This makes it possible to achieve greater performance due to the absence of overhead costs compared to the class being wrapped.
class Wrapper(val underlying: Int) extends AnyVal 

The class must have a single, public val parameter, the type of which will be the type of your class at runtime.
There are some limitations, partly due to the current implementation of the JVM.
docs.scala-lang.org/overviews/core/value-classes.html

Implicit classes


The implicit keyword can now be applied not only to methods, but also to classes. Added to simplify the expansion of existing classes and reduce the burden on implicit methods. Also, obviously, they can have only one parameter (it is possible more if the rest are implicit). In a class, you can only define methods, the exception is a constructor parameter.
Syntax:
 implicit class RichInt(n: Int) extends Ordered[Int] { def min(m: Int): Int = if (n <= m) n else m } 

docs.scala-lang.org/sips/pending/implicit-classes.html
')


String interpolation


 val lang = "Scala" println(s"-  $lang  !") 

In order for the compiler to interpolate a string, before it you need to add a special method - the string interpolator. Out of the box there are three interpolators: s, f and raw.
S allows you to insert variables (put $ in front of them) and expressions (enclose in $ {}) in the string, f formats in the style of the old, good printf, and with raw, as you might guess from the name, you can use escape sequences in the string ( escape sequences) - println (raw "some \ ntext") prints one line, not two.
Does not work with pattern matching yet, but promise to fix to 2.11
 val height = 1.9d val name = "James" println(f"$name%s is $height%2.2f meters tall") // James is 1.90 meters tall 

docs.scala-lang.org/overviews/core/string-interpolation.html

Futures and Promises


New features for parallel programming. The idea is as follows - you can assign a value to an object that does not yet exist. For example, the result of a function that makes an asynchronous request.
 import scala.concurrent._ import ExecutionContext.Implicits.global val session = socialNetwork.createSessionFor("user", credentials) val f: Future[List[Friend]] = future { session.getFriends() } 

docs.scala-lang.org/overviews/core/futures.html

Dynamic


Eliminates some of the drawbacks of static typing.
If you call a method that is not defined for this class and the class extends scala.Dynamic, then the method call is replaced with object.applyDynamic ("methodName") or, depending on the context, with applyDynamicNamed, selectDynamic or updateDynamic.
docs.scala-lang.org/sips/pending/type-dynamic.html

Dependent Method Types


 def identity(x: AnyRef): x.type = x //  ,   


New ASM-based bytecode compiler


Supports JDK 1.5, 1.6 and 1.7. By default it generates bytecode for 1.6. The use of generator 1.5 is not recommended (deprecated).

New Pattern Matcher


Rewritten from scratch to generate better code (no more exponential explosions ). Now the analysis and code generation are independent (the first can be disabled with the -Xno-patmat-analysis key).

Improved Scaladoc




Modularization of functions


To use some advanced and specialized functions, you now need to explicitly import them.
docs.scala-lang.org/sips/pending/modularizing-language-features.html

Ability to configure thread pool for parallel collections


Akka actors now in standard delivery



Improved performance



Added ??? and NotImplementedError


Added classes IsTraversableOnce and IsTraversableLike


Literals for floating-point and octal numbers are now deprecation


Removed scala.dbc



Experimental features




Full list of changes compared to 2.9.2

Source: https://habr.com/ru/post/164739/


All Articles