• 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

Where is the "array".lengh field coming from?

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,
The question might look stupid to you but I have to ask it because I was searching already for one hour into the API DOC : from which super class the "length" field is coming from in the case of, let's say, an int array:

TIA,
Pat
[ April 11, 2003: Message edited by: Pat Metheny ]
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It doesn't come from a super class. The length variable is a final instance variable within the Array class. Look at the JLS, §10.3 Array Creation for more information.
In addition, in the JLS, §10.7 Array Members, I found this:


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


I hope that helps,
Corey
[ April 11, 2003: Message edited by: Corey McGlone ]
 
Pat Metheny
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Valuable answer Corey, thank you.
Yet some short questions: isn't this "array type", which has as direct superclass an Object, defined as a class in Java's class hierarchy? Shouldn't I be able to find it somewhere into the API DOC ? I was looking for example at the Array class but no sign of this public final "length" field.
Many thanks,
Pat
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's a good question and I don't know the answer. I would expect to find it there, as well, but it's not. Anyone know why it was omitted?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Java array types are not something you can subclass or otherwise manipulate so they don't have methods that appear in the JavaDocs.
The Array class is a different animal entirely.
Bill
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Yet some short questions: isn't this "array type", which has as direct superclass an Object, defined as a class in Java's class hierarchy? Shouldn't I be able to find it somewhere into the API DOC ?

Maybe an example would help.
String is a class type. String[] is an array type. Runnable is an interface type. Runnable[] is an array type. int is a primitive type. int[] is an array type.
The API Doc defines the class type String and the interface type Runnable. It does not define the primitive type int or the array types String[], Runnable[] and int[].

from which super class the "length" field is coming from in the case of, let's say, an int array

See page 6, Array Representation
http://www.artima.com/insidejvm/ed2/jvm.html
 
Pat Metheny
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all for the answers, there were really helpful.
Pat
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic