Community
Participate
Working Groups
Code to reproduce bug: public class OverrideGenericsBug { public interface A<T> { <R extends T> A<R> test(); T get(); } public static class B implements A<CharSequence> { @Override public B test() { return this; } @Override public CharSequence get() { return new StringBuilder(); } } public static void main(String[] args) { A<CharSequence> obj = new B(); A<String> what = obj.<String>test(); String string = what.get(); System.out.println(string); } } Eclipse compiler compiled this code without any warning. Javac compiler warning about this code.
So "A" is an interface. "A" has a type TypeVariable "<T>". The method "test()" in "A" returns another "A" but we can change "<T>" to its subtype. Now "B" is ParameterizedType extends "A" and "<T>" parameterized to "CharSequence". The problem is we can override "test()" and returns "B" without any warning. This is looks fine but if we have a varible "A<CharSequence> obj" pointer to object "B". We can just call "obj.<ANY_SUB_TYPE>test()" to let things go wrong. Javac doesn't reject this code but warning about. Because it described in JLS§8.4.5
Found this only now. Agree that ecj should raise a warning, too.
Bulk move out of 4.8
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie.