I'm looking for a way to rewrite the following code using Java 8's functional programming capabilities.
I have a method that returns a list of objects from a database table. If the list is empty then I return a list of objects from a second, different database table. Currently this is how I'm handling this logic:
Simon Ritchie wrote:. . . Can this be accomplished using streams?
Yes, it probably can, but why? Don't go trying to specify an implementation detail at such an early stage in the process.
Thanks Campbell, I hadn't seen that page before. I'm trying to use streams and functional programming as much as possible in my development as I'm trying to get up to speed with the technology and using if statements where I work seems to be looked down on. It's not that they're forbidden but often when code is reviewed I'm encouraged to find a more functional programming solution to conditionality.
posted 1 month ago
. . . and if you get that to run, I shall be very surprised