Nope, you can't do that.
If you need it to stub/mock it, consider using a proxy to access class A, and stub/mock that proxy class instead. E.g., if A.doStuff is what you want to mock/stub, and A.accessStuff is what you need in your code, create a class
class ADecorated(underlying: A) {
def doStuff() {
underlying.doStuff()
// whatever I want to do
}
def accessStuff() {
x = underlying.accessStuff()
// do something else and return
}
// Any other method you want to use
}
Replace usage of A.createA
with new ADecorated(A.createA())
. ADecorated
is what you work with now