资 源 简 介
Unfortunately, java 1.6 does not provide opportunities for functional programming. Also, there are no opportunities for simple expansion of the language.
However, we can use other methods for implementing the elements of functional programming in java.
The following code shows an example of using the library listfunc4j.
@Test public void testForEach() throws Exception { List < Long > myList = Arrays.asList(0L, 1L, 2L, 3L); final int x = 100; forEach(myList) .add(new Lambda() {{ _ = $.intValue(); }}) .add(new Lambda() {{ System.out.println("test " + (_ = $)); }}) .filter(new Filter() {{ _ = ($ > 0); }}) .update(new Updater() {{ System.out.println("more than 0: " + $); }}) .aggregate(new Aggregator(0){{ _ += $; }}) .update(new Updater() {{ System.out.pr