Relates :
|
|
Relates :
|
|
Relates :
|
Consider the following interface and implementor classes: public interface Intf { // public void method1(); } import java.lang.reflect.Method; import java.lang.reflect.InvocationTargetException; public class SubClass implements Intf { public static void main(String[] args) { SubClass sc = new SubClass(); Class paramClasses[] = new Class[]{}; for (int i = 0; i < 20; i++) { try{ System.out.println("Try: " + i); Method method1 = sc.getClass().getMethod("method1",paramClasses); method1.invoke(sc); } catch(NoSuchMethodException nme){ nme.printStackTrace(); } catch(AbstractMethodError ame){ ame.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } } } Steps to reproduce the issue: 1) Compiled both the classes 2) Uncomment method1() in Intf.java 3) recompile only Intf.java We get incompatible class set. Now, run java Subclass You get AbstractMethodError for the first 15 iterations and then get InvocationTargetException that wraps AbstractMethodError. Actually, AbstractMethodError is expected always -- because "method1()" is not implemented in "SubClass" and therefore the linkage should fail always. Throwing InvocationTargetException seem to suggest that the method was called and resulted in some exception being thrown.
|