In the javaodoc for the stream package, at the end of the section Parallelism
, I read:
Most stream operations accept parameters that des
When in doubt simply check the documentation to the specific operation. Examples:
Stream.map mapper parameter:
mapper
- a non-interfering, stateless function to apply to each element
Here documentation explicitly says that the function must be stateless.
Stream.forEach action parameter:
action
- a non-interfering action to perform on the elements
Here it's not specified that the action is stateless, thus it can be stateful.
In general it's always explicitly written on every method documentation.