• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

clone() inherited/overridden(?) in Arrays from Object

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Following is from the JLS
10.7 Array Members
The members of an array type are all of the following:
The public final field length, which contains the number of components of the array (length may be positive or zero)
The public method clone, which overrides the method of the same name in class Object and throws no checked exceptions
All the members inherited from class Object; the only method of Object that is not inherited is its clone method

In the API it specifically mentions that java.util.Arrays inherits all the methods of Object including clone. Nowhere does it mention about the above stmt in the JLS.
Any comments !!?
Ankur
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
java.util.Arrays is NOT the class which defines the java language arrays. There is no predefined class in the JDK for them, a class is created for an array at the runtime, depending on the type of members ( getClass() for an array of ints would print [I.. its superclass wud be Object )
an arrays class is the same as the following class:
class A implements Cloneable, java.io.Serializable {
public final int length = X;
public Object clone()
{
try
{
return super.clone();
}
catch (CloneNotSupportedException e)
{
throw new InternalError(e.getMessage()); }
}
}
---
so it has to implement clone() method in order to implement the Clonable interface, although it eventually calls Object's clone() .
cheers,
Vivek
 
Ankur Gupta
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vivek,
array and Arrays !! It was confusing I guess. Well! now it is clear. Thanks!
Ankur
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic