July 2023
Intermediate to advanced
276 pages
6h 55m
English
As Java programmers, we’ve come to like and extensively use the so-called for-each syntax, which is of the form for(Type variable: iterable). It’s a lot simpler than the traditional for loop when we don’t need the index and care only about the elements in a collection. But it’s not uncommon to use break and continue with both versions of for. The result is verbose code that takes effort to maintain in the long run. Let’s take a stab at refactoring code that uses for-each to functional style.
Keeping up with our tradition, let’s start with the tests:
| | public class AgencyTest { |
| | Agency agency; |
| | |
| | @BeforeEach |
| | public void init() { |
| | agency = new Agency(); |
| | } |
| | |
| | @Test |
| | public ... |
Read now
Unlock full access