| 17 | } |
| 18 | |
| 19 | public class DynamicSupplier<T> implements Supplier<T> { |
| 20 | private Class<T> type; |
| 21 | public DynamicSupplier(Class<T> type) { |
| 22 | this.type = type; |
| 23 | } |
| 24 | @Override public T get() { |
| 25 | try { |
| 26 | return type.getConstructor().newInstance(); |
| 27 | } catch(Exception e) { |
| 28 | throw new RuntimeException(e); |
| 29 | } |
| 30 | } |
| 31 | public static void main(String[] args) { |
| 32 | Stream.generate( |
| 33 | new DynamicSupplier<>(ID.class)) |
| 34 | .skip(10) |
| 35 | .limit(5) |
| 36 | .forEach(System.out::println); |
| 37 | } |
| 38 | } |
| 39 | /* Output: |
| 40 | 10 |
| 41 | 11 |
nothing calls this directly
no outgoing calls
no test coverage detected