GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — OnJava8-Examples/generics/ApplyFunctional.java at master · lliittllee/OnJava8-Examples Expand file tree/ Copy pathApplyFunctional.javaMore file actions 49 lines (46 loc) · 1.18 KB / Copy pathApplyFunctional.javaFile metadata and controls49 lines (46 loc) · 1.18 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 // generics/ApplyFunctional.java // (c)2017 MindView LLC: see Copyright.txt // We make no guarantees that this code is fit for any purpose. // Visit http://OnJava8.com for more book information. import java.util.*; import java.util.stream.*; import java.util.function.*; import onjava.*; public class ApplyFunctional { public static void main(String[] args) { Stream.of( Stream.generate(Shape::new).limit(2), Stream.generate(Square::new).limit(2)) .flatMap(c -> c) // flatten into one stream .peek(Shape::rotate) .forEach(s -> s.resize(7)); new FilledList<>(Shape::new, 2) .forEach(Shape::rotate); new FilledList<>(Square::new, 2) .forEach(Shape::rotate); SimpleQueue<Shape> shapeQ = Suppliers.fill( new SimpleQueue<>(), SimpleQueue::add, Shape::new, 2); Suppliers.fill(shapeQ, SimpleQueue::add, Square::new, 2); shapeQ.forEach(Shape::rotate); } } /* Output: Shape 0 rotate Shape 0 resize 7 Shape 1 rotate Shape 1 resize 7 Square 2 rotate Square 2 resize 7 Square 3 rotate Square 3 resize 7 Shape 4 rotate Shape 5 rotate Square 6 rotate Square 7 rotate Shape 8 rotate Shape 9 rotate Square 10 rotate Square 11 rotate */ |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |