Answer the question
In order to leave comments, you need to log in
Java. How to intercept an argument when calling a method?
There is a singleton object from third-party code, you need to intercept the argument when calling its method.
Or as an alternative, override the method in this object.
Is there such a possibility at all?
Answer the question
In order to leave comments, you need to log in
Your case is rather difficult, but do not forget that reflection is capable of miracles .
PS In python, this (anti-pattern) is called monkey patching.
If you use JavaEE, then you can intercept method calls from EJB beans through an annotation in which you point to the interceptor class. More details here , for example.
If you call the singleton methods, then you can create a duplicate class that will repeat the singleton interface and redirect calls to it + log the passed parameters.
To override methods, one could use the CGLIB library, which can create a class proxy, but since this is a singleton, it is most likely the final class without a public constructor, Java will not allow such an override.
In general, no way.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question