Type the reflective construction of an inner Event by name
Type the reflective construction of an inner Event by name
Answer
Class<?> c = Class.forName("GreenhouseControls$" + name); Constructor<?> ctor = c.getConstructor(GreenhouseControls.class, long.class); Event e = (Event) ctor.newInstance(outer, time);
Class.forName loads by the binary name (outer$inner). An inner class ctor’s first parameter is the enclosing instance, so getConstructor lists GreenhouseControls.class first and newInstance passes `outer` first. No controller recompile is needed to add an event type.