Scala:是否可以定义扩展其 class 参数的 class?

Scala: Is it possible to define a class that extends its class parameter?

我想设计一个 class 作为任何其他 class 的包装。我们称这个包装器为 class Virtual,它的用法如下:

val x: String = "foo"
val y: Virtual[String] = new Virtual(x)
// any method that can be called on x can also be called on y,
// i.e., Virtual[String] <: String

// example:
y.toUpperCase // will change the wrapped string to an upper case

这是我目前拥有的:

class Virtual[T](obj: T) extends T {
  // any Virtual specific methods here
}

扩展类型参数似乎并不能解决问题...

换句话说: 如何确保由 Virtual class 包装的 Virtual class 公开的方法也由 Virtual class 本身公开?

按照评论和 Kevin's answer 中的建议,尝试像这样使用隐式转换

object Hello extends App {
  class Virtual[T](val delegate: T) {
    def bar(i: Int): Int = i + 1
  }
  implicit def VirtualToDelegate[T](virtual: Virtual[T]): T = virtual.delegate
  val str = "foo"
  val virtual = new Virtual[String](str)
  println(virtual.toUpperCase) // FOO
  println(virtual.bar(7))      // 8
}