Hi,

> > BytesRef#clone()'s javadoc comment says that the result will be a
> > shallow clone, sharing the backing array with the original instance,
> > and points to another utility method for deep cloning:
> BytesRef#deepCopyOf(BytesRef).
> 
> There is no hard contract for clone
> https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#clone%
> 28%29
> but the convention, as stated, is "the object returned by this method should
> be independent of this object". That whole section of the Oracle's JavaDocs
> describes the exact opposite of BytesRef clone behaviour.

If you say this, then this constraint would not even be held on the lowest 
level inside the JDK (arrays, collections)! If you have the following:

Object[] array
List<Object> list

And you call:

array2 = Array.clone();
list2 = list.clone();

Both is also shallow! So how is this different?

In fact, the new array and the new list are independent, but this only says 
something about the instance itself (they are really independent, because they 
are 2 different instances, just containing the same data or references). If 
both refer via references to the same things, this is (in my opinion) not 
covered by "be independent of this object".

BytesRef is not different, because it is just a "reference" to pass around. And 
cloning a reference for sure should not clone the target of the reference. You 
are "cloning" the reference and only that (as the name of the class says: 
Bytes*Ref*)!

Uwe


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
For additional commands, e-mail: java-user-h...@lucene.apache.org

Reply via email to