Community
Participate
Working Groups
I200409140800 + jdt.core from HEAD I got an NoSuchMethodError when running this code : import java.util.ArrayList; import java.util.List; class TestElement extends ArrayList implements Runnable { public void run() { } } blic class Test <E extends List & Runnable> { public Test(E element) { element.run(); } public static void main(String[] args) { new Test<TestElement>(new TestElement()); } } Exception in thread "main" java.lang.NoSuchMethodError: java.util.List.run()V at test.Test.<init>(Test.java:13) at test.Test.main(Test.java:16) It looks like the method invocation referenced java.util.List#run() instead of java.lang.Runnable#run(). If I reverse the order of 'List' and 'Runnable' in the type declaration, this test case works (but I expect problems if I try to access List methods).
Reproduced in latest.
Problem comes from change of Runnable#run() receiver type to List#run(), as List is the erasure of type variable. Reversing the order of bounds is changing erasure to Runnable, and then method invocation is legite.
Workaround is to explicitly cast before invoking method from Runnable.
Tweak receiver genericCast insertion. Added regression tests: GenericTypeTest#test320 & test321. Fixed
Verified for 3.1M3 with build I200411040100