Scala: How to extend a third party class with custom attributes -
i need extend external class attribute... , since dynamic
not applied in case, i've no other option create wrapper this:
class mywrapper(val otherclass: otherclass, val myattribute: int) { ... } val mywrapper = new mywrapper(new otherclass, 1)
then, invoke otherclass
members this:
mywrapper.otherclass.foo
is there trick have call this?
mywrapper.foo
i've tried apply
... doesn't work:
class mywrapper(val otherclass: otherclass, val myattribute: int) { def apply = otherclass }
furthermore cannot extend otherclass
this...
class mywrapper(val myattribute: int) extends otherclass { ... }
... since need use factory class deserializes byte array.
you can use pimp library pattern (i believe trying downplay name though). basically, can use implicits accomplish this. in fact, can use implicit class
of 2.10
object pimper{ implicit class wrapperclass(wrapped: otherclass){ def additionalstuff.... } } import pimper._ new otherclass().additionalstuff
there lot on implicits, let research rest on own :)
Comments
Post a Comment