是否可以在没有实际实例化的情况下链接值类?例如:
import scala.swing._
object SwingPlus {
implicit class RichComponent(val self: Component) extends AnyVal {
def clientProps: ClientProperties = new ClientProperties(self)
}
implicit class ClientProperties(val self: Component) extends AnyVal {
def += (kv: (String, Any)): Component = {
self.peer.putClientProperty(kv._1, kv._2)
self
}
}
}
用例:
import SwingPlus._
val b = Button("Foo") { println("bar") }
b.clientProps += "JButton.buttonType" -> "textured"
val f = new Frame { contents = but; pack(); open() }
在调用b.clientProps +=
中,是否ClientProperties
被实例化,或者这些只是纯静态(优化)方法调用?