Using multimethods we are able to add methods to existing Java classes. My question is whether it is possible to redefine one specific method, and how, from Clojure code. For instance, if you have the following class,
public class Shape {
public void draw() {
...
}
}
I'd like to be able to run something to add a before method, such as this:
(attach-to-method Shape/draw :before
(println "... about to draw a shape"))
And after evaluating that form, all subsequent calls to draw would start printing a string before performing the call itself.
My purpose with this attachment of before/after/around, AOP-like behavior, is that a framework calling that method on an existing instance can be dynamically changed and start running the newly-attached code. Currently I'm using AspectJ for that, but I'm getting to a point where using a different compiler isn't an option, and I'm curious to know if I can just ditch AspectJ.