Given a java.lang.reflect.Method
object, is there anyway to determine whether the method is purely functional (i.e., given the same input, it will always produce the same output and it is stateless. In other words, the function does not depend on its environment)?
Determine if a static method is purely functional
435 views Asked by One Two Three At
5
There are 5 answers
3
On
No there is no way to do that with reflection or any other mechanism.
The developer knows if the method is functional. For example, Spring has a @Cacheable
annotation that gives a hint to the application that the method is functional and can therefore cache the result for a given set of arguments. (Spring will wrap your object in a proxy that provides the caching behavior.)
No, there's no way to do it.
Reflection does not allow you to inspect the actual code behind the method.
And even if that where possible, the actual analysis would probably be ... tricky, to say the least.