How to make scala volatile type with goal

According to http://www.scala-lang.org/files/archive/spec/2.11/03-types.html#volatile-types , types are unstable when they meet specific conditions. Is it possible to make a type mutable (e.g. annotation) that does not apply to this form? What are the alternatives?

My use case is this: I want to write a library that provides Aboth Bs A <: Band s types and Bmutably. Then, as a user of this library, I want to be able to overwrite the type value with Aone of the types B:

trait TraitB {
  def doSomething: Unit
}

trait Library {
  type A
  type B <: A with TraitB
}

object LibraryUser {
  val library: Library = ???

  trait T {
    val x: library.A
  }

  object U extends T {
    val x: library.B = ???
  }
}

Error with error:

: x T LibraryUser.library.A; x ;

A volatile, . A volatile, Abstract, Any :

trait TraitB {
  def doSomething: Unit
}

trait Library2 {
  protected type Abstract
  type A <: Any with Abstract
  type B <: A with TraitB
}

trait Library2ImplementationHelper {
  this: Library2 =>
  override type Abstract = Any
}

object Library2User {
  val library: Library2 = ???

  trait T {
    val x: library.A
  }

  object U extends T {
    val x: library.B = ???
  }
}

, Abstract , , .

+4
1

@volatile , , var . , Java.

, SoVolatile.scala:

class SoVolatile {
  @volatile var boom = 5
}

:

$ scalac SoVolatile.scala
$ javap -verbose -private SoVolatile

private volatile int boom;. , :

$ javap -verbose -private SoVolatile | grep "private volatile"
-1

All Articles