diff --git a/TAP4/src/dynamic/DynamicProxy.java b/TAP4/src/dynamic/DynamicProxy.java index b1a9ce1..f403152 100644 --- a/TAP4/src/dynamic/DynamicProxy.java +++ b/TAP4/src/dynamic/DynamicProxy.java @@ -9,10 +9,10 @@ * Created by milax on 20/10/15. */ public class DynamicProxy implements InvocationHandler { - private Object target = null; + private final Object target; public static Object newInstance(Object target){ - Class targetClass = target.getClass(); - Class interfaces[] = targetClass.getInterfaces(); + Class targetClass = target.getClass(); + Class[] interfaces = targetClass.getInterfaces(); return Proxy. newProxyInstance(targetClass.getClassLoader(), interfaces, new DynamicProxy(target)); } @@ -20,7 +20,7 @@ private DynamicProxy(Object target) { this.target = target; } - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable{ + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Object invocationResult = null; try { @@ -36,9 +36,7 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl { System.err.println("Invocation of " + method.getName() + " failed"); } - finally{ - return invocationResult; - } + return invocationResult; } } \ No newline at end of file diff --git a/TAP4/src/reflection/InspectTest.java b/TAP4/src/reflection/InspectTest.java index f7fcea0..4f1d988 100644 --- a/TAP4/src/reflection/InspectTest.java +++ b/TAP4/src/reflection/InspectTest.java @@ -10,17 +10,17 @@ public class InspectTest { public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { - Class aClass =Class.forName("reflection.Person"); - Method nameMethod=aClass.getDeclaredMethod("getName"); - Object newObject = aClass.newInstance(); - String output =(String) nameMethod.invoke(newObject); + Class aClass = Class.forName("reflection.Person"); + Method nameMethod = aClass.getDeclaredMethod("getName"); + Object newObject = aClass.getDeclaredConstructor().newInstance(); + String output = (String) nameMethod.invoke(newObject); System.out.println(output); - Person p1 = (Person)newObject; + Person p1 = (Person) newObject; System.out.println(p1.getName()); - for (Method method:aClass.getDeclaredMethods()) + for (Method method : aClass.getDeclaredMethods()) System.out.println(method.getName()); }