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

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Shai Erera
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
Reply | Threaded
Open this post in threaded view
|

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

Uwe Schindler

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: [hidden email]

 

From: Shai Erera [mailto:[hidden email]]
Sent: Wednesday, July 14, 2010 9:40 AM
To: [hidden email]
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

Reply | Threaded
Open this post in threaded view
|

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

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

Shai

On Wed, Jul 14, 2010 at 10:47 AM, Uwe Schindler <[hidden email]> 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: [hidden email]

 

From: Shai Erera [mailto:[hidden email]]
Sent: Wednesday, July 14, 2010 9:40 AM
To: [hidden email]
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


Reply | Threaded
Open this post in threaded view
|

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

Uwe Schindler
In reply to this post by Uwe Schindler

Issue is: https://issues.apache.org/jira/browse/LUCENE-2000

 

Uwe

 

-----

Uwe Schindler

H.-H.-Meier-Allee 63, D-28213 Bremen

http://www.thetaphi.de

eMail: [hidden email]

 

From: Uwe Schindler [mailto:[hidden email]]
Sent: Wednesday, July 14, 2010 9:47 AM
To: [hidden email]
Subject: RE: Proposal - change classes that impl Cloneable to return a specific value

 

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: [hidden email]

 

From: Shai Erera [mailto:[hidden email]]
Sent: Wednesday, July 14, 2010 9:40 AM
To: [hidden email]
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

Reply | Threaded
Open this post in threaded view
|

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

Shai Erera
Why is the issue still open?

On Wed, Jul 14, 2010 at 10:53 AM, Uwe Schindler <[hidden email]> wrote:

Issue is: https://issues.apache.org/jira/browse/LUCENE-2000

 

Uwe

 

-----

Uwe Schindler

H.-H.-Meier-Allee 63, D-28213 Bremen

http://www.thetaphi.de

eMail: [hidden email]

 

From: Uwe Schindler [mailto:[hidden email]]
Sent: Wednesday, July 14, 2010 9:47 AM

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

 

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: [hidden email]

 

From: Shai Erera [mailto:[hidden email]]
Sent: Wednesday, July 14, 2010 9:40 AM
To: [hidden email]
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


Reply | Threaded
Open this post in threaded view
|

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

Andrzej Białecki-2
On 2010-07-14 09:59, Shai Erera wrote:
> Why is the issue still open?
>
> On Wed, Jul 14, 2010 at 10:53 AM, Uwe Schindler <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Issue is: https://issues.apache.org/jira/browse/LUCENE-2000

It's a Y2K bug...

;)

--
Best regards,
Andrzej Bialecki     <><
  ___. ___ ___ ___ _ _   __________________________________
[__ || __|__/|__||\/|  Information Retrieval, Semantic Web
___|||__||  \|  ||  |  Embedded Unix, System Integration
http://www.sigram.com  Contact: info at sigram dot com


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]