Eclipse reporting an array's clone() method is from it's corresponding type (including primitives)? Eclipse reporting an array's clone() method is from it's corresponding type (including primitives)? arrays arrays

Eclipse reporting an array's clone() method is from it's corresponding type (including primitives)?


This can only be answered by looking at the eclipse source code.

The answer for your question is simple and disappointing: The Eclipse UI code which produces the complete proposals builds a faulty display. Note that the complete proposal for the length property of an array shows the correct type (byte[] in your example).

The details:

When you trigger the completion assistant the possible completions are calculated as CompletionProposals.

The property of the CompletionProposals which is used to display the type of a proposed method or field completion is the declaringTypeSignature (see below).

CompletionTests shows that proposal objects for the clone-method and the length-field of a byte array would have a declaringTypeSignature "[B".

Now CompletionProposalLabelProvider takes these proposal objects and builds the view, in the form of a StyledString. Method #createLabelWithTypeAndDeclaration does it for field proposals, method #createMethodProposalLabel for method proposals. They have different implementations for the display of the declaring type.

The method display calls SignatureUtil.stripSignatureToFQN, passing "[B" as signature. The returned result has stripped of all array information and is simply "byte".

The field display calls Signature.getSignatureSimpleName passing "[B". This method does not ignore the array information and returns "byte[]".


This is because cloning depends on the type of the object. It depends on the memory size of the objects or primitive data types.

clone() method is actually the method of the 'Object' superclass. Other classes are supposed to override this and implement their own implementation for safe cloning. If nothing is provided, the normal cloning of Object class is called and implemented.

That is why, cloning an array depends on the type of data that array holds and the clone method of that data type will be called. If you have an int[], clone for int will be called. if you have Class A, and 'a' is the object of class A, and you have array of 'a' objects (a[]), clone from class A will be called.

Hope that answers your question.