What are the biggest differences between Scala 2.8 and Scala 2.7?

前端 未结 5 2182
礼貌的吻别
礼貌的吻别 2020-12-04 09:00

I\'ve written a rather large program in Scala 2.7.5, and now I\'m looking forward to version 2.8. But I\'m curious about how this big leap in the evolution of Scala will aff

5条回答
  •  [愿得一人]
    2020-12-04 09:57

    Here's a checklist from Eric Willigers, who has been using Scala since 2.2. Some of this stuff will seem dated to more recent users.

    * Explicitly import from outer packages *

    Suppose we have

    package a
    class B
    

    Change

    package a.c
    class D extends B
    

    to

    package a.c
    import a.B
    class D extends B
    

    or

    package a
    package c
    class D extends B
    

    * Use fully qualified package name when importing from outer package *

    Suppose we have

    package a.b
    object O { val x = 1 }
    

    Change

    package a.b.c
    import b.O.x
    

    to

    package a.b.c
    import a.b.O.x
    

    * When explicitly specifying type parameters in container method calls, add new type parameters *

    Change

    list.map[Int](f)
    

    to

    list.map[Int, List[Int]](f)
    

    Change

    map.transform[Value](g)
    

    to

    map.transform[Value, Map[Key, Value]](g)
    

    * Create sorted map using Ordering instead of conversion to Ordered *

     [scalac]  found   : (String) => Ordered[String]
     [scalac]  required: Ordering[String]
     [scalac]         TreeMap[String, Any](map.toList: _*)(stringToCaseInsensitiveOrdered _)
    

    * Import the implicit conversions that replace scala.collection.jcl *

    * Immutable Map .update becomes .updated *

    *** Migrate from newly deprecated List methods --
    * elements * remove * sort * List.flatten(someList) * List.fromString(someList, sep) * List.make

    *** Use List methods * diff * iterator * filterNot * sortWith * someList.flatten * someList.split(sep) * List.fill

    * classpath when using scala.tools.nsc.Settings *

    http://thread.gmane.org/gmane.comp.lang.scala/18245/focus=18247 settings.classpath.value = System.getProperty("java.class.path")

    * Avoid error: _ must follow method; cannot follow (Any) => Boolean *

    Replace

    list.filter(that.f _)
    

    with

    list.filter(that f _)
    

    or

    list.filter(that.f(_))
    

    > > >

    * Migrate from deprecated Enumeration methods iterator map * Use Enumeration methods values.iterator values.map

    * Migrate from deprecated Iterator.fromValues(a, b, c, d) * Use Iterator(a, b, c, d)

    * Avoid deprecated type Collection * Use Iterable instead

    * Change initialisation order *

    Suppose we have

    trait T {
      val v
      val w = v + v
    }
    

    Replace

    class C extends T {
      val v = "v"
    }
    

    with

    class C extends {
      val v = "v"
    } with T
    

    * Avoid unneeded val in for (val x <- ...) *

    * Avoid trailing commas *

提交回复
热议问题