lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Uwe Schindler" <...@thetaphi.de>
Subject RE: Proposal - change classes that impl Cloneable to return a specific value
Date Wed, 14 Jul 2010 07:47:00 GMT
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 <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


Mime
View raw message