You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by Shai Erera <se...@gmail.com> on 2010/07/14 09:51:23 UTC

Re: Proposal - change classes that impl Cloneable to return a specific value

I see. In that case let's leave things as they are :)

Shai

On Wed, Jul 14, 2010 at 10:47 AM, Uwe Schindler <uw...@thetaphi.de> wrote:

> There was an issue in Lucene 3.0.0 development when the generics policeman
> did this. The return type of clone() with covariant override was not done,
> because of several backwards compatibility problems from 2.9->3.0. The
> problem with covariant clone() is that **every** superclass must do
> covariant clone, else you get problems with wrong method is called (this is
> a known issue, so most people even Java JDK itself does not do covariant
> clone!).
>
>
>
> Because of this it’s always better to clone and cast later. This is much
> more secure, with mixed covariant-clone / object-clone you introduce not
> easy to see bugs.
>
>
>
> -----
>
> Uwe Schindler
>
> H.-H.-Meier-Allee 63, D-28213 Bremen
>
> http://www.thetaphi.de
>
> eMail: uwe@thetaphi.de
>
>
>
> *From:* Shai Erera [mailto:serera@gmail.com]
> *Sent:* Wednesday, July 14, 2010 9:40 AM
> *To:* dev@lucene.apache.org
> *Subject:* Proposal - change classes that impl Cloneable to return a
> specific value
>
>
>
> Hi
>
> When you implement Cloneable, you need to implement clone(), which by
> default is declared as returning Object. However, you can change the return
> value to be a more specific one, while still be considered as implementing
> Cloneable. We also anyway override clone() and change its visibility to
> public.
>
> I'd like to change the classes that impl it to return a more specific type.
> For example, IndexInput will return IndexInput. This saves the casting done
> later on.
>
> This is not a perf issue, but more of style.
>
> What do you think? Does anyone see any problem with it?
>
> Shai
>