Is it possible in Scala to make some mixin to class instance?
Eg: I have some MyClass instance var x = new MyClass and I want to extend it on some method or trait without copying it.
[Edit:]
I’m looking the way to extend x after it has been instantiated.
So, for example in a function method, which gets x as a parameter.
[What is behind]
I’ve just wonder if there is some magic with implicit objects and Manifest to achieve the typeclass pattern without explicit call implicit object (like in Haskell).
But only for single object.
I know if is artificial, but I’ve just wonder if it’s possible because of lot of magic with mixing Scalas features.
It is not possible. You may look at using the
Dynamictrait or Kevin Wright’s auto-proxy plugin, but, either way, you’ll create a new object that also answers to the original one’s method through proxying.