jdevelop
jdevelop

Reputation: 12306

scala and abstract type "unboxing"

Given classes

object A {
  type URLT = String
}

case class A(url : URLT)

class ForeignStreamWriter {
  def writeString(str: String) {}
}

trait WriterA {

  val writer : ForeignStreamWriter

  def write(src: A) {
    writer.write(src.url)
  }
}

how can I tell the compiler that I'm working with String - not URLT - in writer.write(src.url)? I can not modify signature of ForeignStreamWriter.

UPD

As for now I found the only solution

  def write(src: A) {
    writer.write(src.url.asInstanceOf[String])
  }

but I don't really like it.

Upvotes: 0

Views: 107

Answers (1)

Sergey Passichenko
Sergey Passichenko

Reputation: 6930

You need to import A._ in scope. By the way, your sample didn't compile without it.

Upvotes: 1

Related Questions