MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / DynamicSupplier

Class DynamicSupplier

reflection/DynamicSupplier.java:19–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17}
18
19public 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:
4010
4111

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected