Override annotation preventing compilation

1,103 views
Skip to first unread message

mmoossen

unread,
May 25, 2010, 6:19:04 AM5/25/10
to Google Web Toolkit
Dear all,

I have a serializable object that overrides the Object.clone() method
and implements the cloneable interface.
and i have the problem that eclipse (and me too) wants to have the
Override annotation but while compiling the GWT compiler fails with
following error message

[java][ERROR] Line 175: The method clone() of type XXX must override
or implement a supertype method

which sounds pretty much like a bug in the GWT compiler to me... i
mean, why does the GWT compiler care about those annotations? and more
over, why does it *FAIL*.

could somebody explain the issue to me?

thanks
Michael

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Sripathi Krishnan

unread,
May 25, 2010, 6:40:27 AM5/25/10
to google-we...@googlegroups.com
I think it is the javac compiler failing, not GWTC. Also, I'd guess you are using JDK 1.5.

In JDK 1.5, @Override annotation cannot be applied to methods that implement an interface; they can only be applied to a method that overrides a method from a class. In your case, the clone method is defined in an interface, and you are implementing it, not overriding it .. and hence the error.

Java 6 onwards, you can apply the @Override annotation to methods that implement an interface.. so you won't get this warning. Strangely, using Java 6 compiler with source="1.5" does not trigger this error.

Finally, eclipse is the third culprit. It automatically puts in those annotations, and I haven't yet figured out a way to tell it "don't put those annotations when I am implementing an interface"..

--Sri

mmoossen

unread,
May 25, 2010, 8:05:40 AM5/25/10
to Google Web Toolkit
hi Sri!

i thought it was something like that but:
- i am using java 1.6
- clone() is a method in Object and not in the interfac, and
- as said, eclipse wants that annotation (if not i get a warning) and
i get an error only when compiling client code.

thanks anyhow
Michael

On May 25, 12:40 pm, Sripathi Krishnan <sripathi.krish...@gmail.com>
wrote:
> I think it is the javac compiler failing, not GWTC. Also, I'd guess you are
> using JDK 1.5.
>
> In JDK 1.5, @Override annotation cannot be applied to methods that implement
> an interface; they can only be applied to a method that overrides a method
> from a class. In your case, the clone method is defined in an interface, and
> you are implementing it, not overriding it .. and hence the error.
>
> Java 6 onwards, you can apply the @Override annotation to methods that
> implement an interface.. so you won't get this warning. Strangely, using
> Java 6 compiler with source="1.5" does not trigger this error.
>
> Finally, eclipse is the third culprit. It automatically puts in those
> annotations, and I haven't yet figured out a way to tell it "don't put those
> annotations when I am implementing an interface"..
>
> --Sri
>
> On 25 May 2010 15:49, mmoossen <mmoos...@gmail.com> wrote:
>
>
>
> > Dear all,
>
> > I have a serializable object that overrides the Object.clone() method
> > and implements the cloneable interface.
> > and i have the problem that eclipse (and me too) wants to have the
> > Override annotation but while compiling the GWT compiler fails with
> > following error message
>
> > [java][ERROR] Line 175: The method clone() of type XXX must override
> > or implement a supertype method
>
> > which sounds pretty much like a bug in the GWT compiler to me... i
> > mean, why does the GWT compiler care about those annotations? and more
> > over, why does it *FAIL*.
>
> > could somebody explain the issue to me?
>
> > thanks
> > Michael
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Google Web Toolkit" group.
> > To post to this group, send email to google-we...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > google-web-tool...@googlegroups.com<google-web-toolkit%2Bunsu...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/google-web-toolkit?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
> To post to this group, send email to google-we...@googlegroups.com.
> To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/google-web-toolkit?hl=en.

Paul Robinson

unread,
May 25, 2010, 8:56:29 AM5/25/10
to google-we...@googlegroups.com
GWT does not emulate the clone() method on Object, so when you compile
client-side code there is no method for your clone() to override.

Paul

mmoossen

unread,
May 25, 2010, 10:08:52 AM5/25/10
to Google Web Toolkit
hi Paul!

thanks for the insight!
but would it make more sense to have that method throwing by default
an UnsupportedOperationException or something similar so that people
that override that method can compile their classes?
(btw, i now that you should not use the clone() pattern, but this is a
legacy class i can not change)

issue created:
http://code.google.com/p/google-web-toolkit/issues/detail?id=4972

regards,
Michael

Paul Robinson

unread,
May 25, 2010, 10:18:10 AM5/25/10
to google-we...@googlegroups.com
You should be able to implement clone(), you just can't have the
@Override annotation on it.
Reply all
Reply to author
Forward
0 new messages