From 97854ff9b1e9beb1ebe91528ac89df12cfd15ca5 Mon Sep 17 00:00:00 2001 From: Mariusz Date: Tue, 21 May 2019 18:21:59 +0200 Subject: [PATCH] Rozwiazanie zadania --- src/main/java/pl/javastart/Runner.java | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/pl/javastart/Runner.java b/src/main/java/pl/javastart/Runner.java index 725a2f6..53aad8d 100644 --- a/src/main/java/pl/javastart/Runner.java +++ b/src/main/java/pl/javastart/Runner.java @@ -1,7 +1,26 @@ package pl.javastart; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Scanner; + class Runner { - public static void main(String[] args) { + public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, InvocationTargetException { //TODO + + Scanner scanner = new Scanner(System.in); + String className = scanner.nextLine(); // Należy przekazać pl.javastart.Tricky + String params = "JavaStart"; + + Class c = Class.forName(className); + Constructor ctorlist[] = c.getDeclaredConstructors(); + Method methlist[] = c.getDeclaredMethods(); + + Constructor ct = ctorlist[0]; + ct.setAccessible(true); + Method m = methlist[0]; + Object o = ct.newInstance(params); + m.invoke(o); } -} +} \ No newline at end of file