0
我需要擴展一個屬性的外部類...因爲dynamic
無法應用在這種情況下,我沒有其他選擇,而不是創建一個類似的包裝這樣的:Scala:如何擴展第三方類的自定義屬性
class MyWrapper(val otherClass: OtherClass, val myAttribute: Int) {
...
}
val myWrapper = new MyWrapper(new OtherClass, 1)
然後,我調用OtherClass
成員如下:
myWrapper.otherClass.foo
有什麼竅門有一個這樣的電話嗎?
myWrapper.foo
我試着apply
...但它不工作:
class MyWrapper(val otherClass: OtherClass, val myAttribute: Int) {
def apply = otherClass
}
而且我不能延長OtherClass
這樣的...
class MyWrapper(val myAttribute: Int) extends OtherClass {
...
}
...因爲我需要使用從字節數組中反序列化的工廠類。