MCPcopy Create free account
hub / github.com/BruceEckel/OnJava8-Examples / get

Method get

reflection/pets/Creator.java:16–27  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14 // The different types of Pet to create:
15 public abstract List<Class<? extends Pet>> types();
16 @Override public Pet get() { // Create one random Pet
17 int n = rand.nextInt(types().size());
18 try {
19 return types().get(n)
20 .getConstructor().newInstance();
21 } catch(InstantiationException |
22 NoSuchMethodException |
23 InvocationTargetException |
24 IllegalAccessException e) {
25 throw new RuntimeException(e);
26 }
27 }
28 public Stream<Pet> stream() {
29 return Stream.generate(this);
30 }

Callers

nothing calls this directly

Calls 4

typesMethod · 0.95
newInstanceMethod · 0.80
getMethod · 0.65
sizeMethod · 0.45

Tested by

no test coverage detected