Community
Participate
Working Groups
Build Identifier: 20100218-1602 "Name clash: The method convert(A) of type DTOAdapter<A,B> has the same erasure as convert(B) of type TwoWayDTOAdapter<A,B> but does not override it" however changing method order in the implementing class resolve the error Reproducible: Always Steps to Reproduce: public interface DTOAdapter<A, B> { public B convert(A a); } public interface TwoWayDTOAdapter<A, B> extends DTOAdapter <A, B>{ public A convert(B b) throws AdapterException; } this doesn't work and gives the above description error : public class TestAdapter implements TwoWayDTOAdapter<Long, Integer> { public Long convert(Integer b) throws AdapterException { // TODO Auto-generated method stub return null; } public Integer convert(Long a) throws AdapterException { // TODO Auto-generated method stub return null; } } this works, however I just inverted method declaration order : public class TestAdapter implements TwoWayDTOAdapter<Long, Integer> { public Integer convert(Long a) throws AdapterException { // TODO Auto-generated method stub return null; } public Long convert(Integer b) throws AdapterException { // TODO Auto-generated method stub return null; } } inverting the types, with the faulty order like in the first case make it work : public class TestAdapter implements TwoWayDTOAdapter<Integer,Long> { public Long convert(Integer b) throws AdapterException { // TODO Auto-generated method stub return null; } public Integer convert(Long a) throws AdapterException { // TODO Auto-generated method stub return null; } } Note that when generating the stub, eclipse gives the wrong order
(In reply to comment #0) > Build Identifier: 20100218-1602 Can you please test with a more recent build say 3.7 or so. I could not reproduce this on 3.7. I also verified that this works as expected on HEAD. I plan to close this as WORKSFORME.
(In reply to comment #1) > (In reply to comment #0) > > Build Identifier: 20100218-1602 > > Can you please test with a more recent build say 3.7 or so. > I could not reproduce this on 3.7. I also verified that this > works as expected on HEAD. > > I plan to close this as WORKSFORME. I tested it on eclipse 3.7M6 and it compiles in all cases. However some people report me that it doesn't work with javac
(In reply to comment #2) > (In reply to comment #1) > > (In reply to comment #0) > > > Build Identifier: 20100218-1602 > > > > Can you please test with a more recent build say 3.7 or so. > > I could not reproduce this on 3.7. I also verified that this > > works as expected on HEAD. > > > > I plan to close this as WORKSFORME. > > I tested it on eclipse 3.7M6 and it compiles in all cases. > > However some people report me that it doesn't work with javac I tested and it doesnt build with javac 1.5, however the eclipse bytecode runs on the jvm from the jdk1.5.0_21 $ /cygdrive/c/Program\ Files/Java/jdk1.5.0_21/bin/javac.exe *.java TestAdapter.java:4: name clash: convert(B) in fr.test.TwoWayDTOAdapter<java.lang.Long,java.lang.Integer> and convert(A) in fr.test.DTOAdapter<java.lang.Long,java.lang.Integer> have the same erasure, yet neither overrides the other public class TestAdapter implements TwoWayDTOAdapter<Long, Integer> { ^ 1 error
The program attached to comment 0 fails to compile with eclipse 3.7, 3.7 M6 as well as HEAD, not with the name clash error reported, but due to the fact that overriding method attempts to throw exceptions not listed in the throws clause of the overridden method. I see the same behavior with javac 5,6,7 - All of them complain about the throws clause. So I don't know how you managed to run the program - It is likely you are using slightly modified tests. Please post the exact test case you are using so we can be on the same page.
(In reply to comment #4) > The program attached to comment 0 fails to compile with > eclipse 3.7, 3.7 M6 as well as HEAD, not with the name > clash error reported, but due to the fact that overriding > method attempts to throw exceptions not listed in the > throws clause of the overridden method. > > I see the same behavior with javac 5,6,7 - All of them > complain about the throws clause. So I don't know how > you managed to run the program - It is likely you are > using slightly modified tests. Please post the exact test > case you are using so we can be on the same page. Here is the exception code. The code you mention works if "throws AdapterException" is removed everywhere though. public class AdapterException extends RuntimeException { /** * */ private static final long serialVersionUID = 4296648530651520598L; public AdapterException() { super(); // TODO Auto-generated constructor stub } public AdapterException(String message, Throwable cause) { super(message, cause); // TODO Auto-generated constructor stub } public AdapterException(String message) { super(message); // TODO Auto-generated constructor stub } public AdapterException(Throwable cause) { super(cause); // TODO Auto-generated constructor stub } }
here is the code without the exception public interface DTOAdapter<A, B> { public B convert(A a); } public interface TwoWayDTOAdapter<A, B> extends DTOAdapter <A, B>{ public A convert(B b); } public class TestAdapter implements TwoWayDTOAdapter<Long, Integer> { public Long convert(Integer b) { // TODO Auto-generated method stub return null; } public Integer convert(Long a) { // TODO Auto-generated method stub return null; } }
Thanks, I do see a difference in behavior and will investigate. Changed the title suitably.
(In reply to comment #7) > Thanks, I do see a difference in behavior and will investigate. > Changed the title suitably. I don't really see why it shouldn't work on javac either. I understand that in case the given type for A and B are the same, then it wouldn't work obviously, but it would be dectected at compile time anyway at the implementor level.
Released junit org.eclipse.jdt.core.tests.compiler.regression.MethodVerifyTest.test342819() *** This bug has been marked as a duplicate of bug 334306 ***
Verified that the code doesn't compile. For comment 6, the error is reported against: public A convert(B b);