Is there a function which accepts a reference to a lambda expression and returns a boolean saying whether the lambda expression is stateless or not? How can the statefulness of
I would argue that it is not possible to write a function that can determine if a lambda is stateless or not:
Looking for example at the filter
method of the Stream API, the javadoc states that the parameter must be "a [...] stateless predicate" and also links to the API's definition of stateless.
If there was a way to determine if the parameter of the filter
(or any other) method was stateless or not, the Stream class would have included the possibility to throw an IllegalArgumentException in case the parameter was a stateful lambda. As this has not been implemented and only a warning was added to the javadocs, one can conclude that there is no way write a function that can determine if a lambda lambda is stateless.