I would like to know if having an instance to which a trait has been added to in runtime, it is possible to remove the trait off the instance, so it can behave as originally.
Traits are combined with classes at compile-time. So it is not possible to add/remove traits at run-time.
For your particular case, consider adding a method to your class:
class Foo(val a: Object, val b: Object, ...) {
def original() = new Foo(a, b, ...)
}
Then you can call instance.original()
to get back a copy of your object that is not affected by any traits.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With