Type the reflective Event factory body
Type the reflective Event factory body
Answer
Class<?> c = Class.forName(name); Constructor<?> ctor = c.getConstructor(long.class); return (Event) ctor.newInstance(time);
Class.forName loads the class by name; getConstructor(long.class) finds the public Event(long) constructor; newInstance(time) calls it and the result is cast to Event. This is the exact pattern the Greenhouse Part-2 event factory uses to add events without recompiling.