Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement interface with object.Clone conflicting method

I'd like to create a mock of this XQPart interface. The problem is that it extends an interface called XQCloneable which has a clone method.

When I in Eclipse create a new class with this set as an interface, I get this class:

public class Part implements XQPart {}

With a red error squiggly under Part saying

CloneNotSupportedException in throws clause of Object.clone() is not compatible with XQCloneable.clone()

What can I do here? Is there no way to make an implementation of this interface?


Note: I did try to implement the method, but didn't realize I could skip the throws declaration as told in accepted answer so kept getting that error.

like image 389
Svish Avatar asked Nov 12 '12 13:11

Svish


1 Answers

Your class inherits Object.clone, which is declared to throw CloneNotSupportedException. On the other hand, your class implements XQCloneable, whose clone has no throws clause. If you just create an empty declaration public Object clone() { return null; }, it will make your class compatible with the interface.

like image 106
Marko Topolnik Avatar answered Oct 30 '22 17:10

Marko Topolnik