0

簡単なサンプル ソースを考えると、コピー コンストラクターと暗黙的な変換メソッドを作成できる必要があります。Scala 2.10 と新しいマクロ機能を使ってこれを達成する方法を教えてください。

import java.util.UUID

object Sample {

  case class Entity(id: UUID, name: String)

  trait Storable {

    val storageId: UUID

  }

  trait Storage {

    type T <: Entity with Storable

    def save(src: T) : T

  }

  class StorageImpl extends Storage {

    type T = Entity with Storable

    def save(src: StorageImpl#T): StorageImpl#T = null
  }

  def getEntity() = Entity(UUID.randomUUID(), "Test")

  def main(args: Array[String]) {
    val storage = new StorageImpl
    val entity = getEntity() // get this from some third-party module
    storage.save(entity) // HOW?! Create copy constructor and implicit?
  }

}
4

0 に答える 0