dimanche 16 août 2015

Scala: replace method at runtime

Let's say I have a class

class Original {
  def originalMethod = 1
}

Now, let's say I have an instance of it

val instance = new Original

Is it now possible to do something to instance at runtime to replace the originalMethod with a different method? (granted the signature stays the same)

For example, now, when calling instance.originalMethod the following code will be called println("test"); 1

PS. I stumbled on this question when trying to mimic a Mockito spy





Aucun commentaire:

Enregistrer un commentaire