Overriding a method in an instantiated Java object

前端 未结 9 1560
陌清茗
陌清茗 2021-02-05 01:55

I would like to override a method in an object that\'s handed to me by a factory that I have little control over.

My specific problem is that I want to override the

9条回答
  •  忘掉有多难
    2021-02-05 02:09

    You can't really change an object on the fly in java.

    You could have something which do what you want by wrapping your Foo into another similar objet which will delegate every call to Foo and at the same log everything you want. (see Proxy)

    But if you want to do logging, maybe aspect is a better choice. (see AspectJ)

提交回复
热议问题