473,729 Members | 2,142 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Arrays - component type vs Element type

Can anyone explain to me the difference between an element type and a
component type?

In the java literature, arrays are said to have component types, whereas
collections from the Collections Framework are said to have an element
type.
http://java.sun.com/docs/books/jls/s...rrays.doc.html

states:
The *component type* of an array may itself be an array type. The components of
such an array may contain references to subarrays. If, starting from any
array type, one considers its component type, and then (if that is also an
array type) the component type of that type, and so on, eventually one must
reach a component type that is not an array type; this is called the *element
type* of the original array, and the components at this level of the data
structure are called the elements of the original array.

Reading that - I thought I'd 'got' the difference, but then in 10.1 (a
para later) the terms seem to used synonomously!
An array type is written as the name of an *element type* followed by some
number of empty pairs of square brackets []. The number of bracket pairs
indicates the depth of array nesting. An array's length is not part of its
type.
The element type of an array may be any type, whether primitive or reference.
In particular:

€ Arrays with an interface type as the *component type* are allowed. The
elements of such an array may have as their value a null reference or
instances of any type that implements the interface.
€ Arrays with an abstract class type as the *component type* are allowed.
The elements of such an array may have as their value a null reference or
instances of any subclass of the abstract class that is not itself
abstract.


When describing collections from the Collections framework there is
never any of this ambiguity/distinction - it is always "element type",
even when talking about a collection whose elements are themselves
collections.

Am I missing a "big idea"?

Any thoughts greatly appreciated.

Rob

r.***********@o pen.ac.uk
Jan 22 '06 #1
1 8704
"Rob Griffiths" <r.***********@ open.ac.uk> wrote in message
news:r.******** *************** **********@euro pe.isp.giganews .com...
Can anyone explain to me the difference between an element type and a
component type?

In the java literature, arrays are said to have component types, whereas
collections from the Collections Framework are said to have an element
type.
http://java.sun.com/docs/books/jls/s...rrays.doc.html

states:
The *component type* of an array may itself be an array type. The
components of
such an array may contain references to subarrays. If, starting from any
array type, one considers its component type, and then (if that is also
an
array type) the component type of that type, and so on, eventually one
must
reach a component type that is not an array type; this is called the
*element
type* of the original array, and the components at this level of the data
structure are called the elements of the original array.

Reading that - I thought I'd 'got' the difference, but then in 10.1 (a
para later) the terms seem to used synonomously!
An array type is written as the name of an *element type* followed by
some
number of empty pairs of square brackets []. The number of bracket pairs
indicates the depth of array nesting. An array's length is not part of
its
type.
The element type of an array may be any type, whether primitive or
reference.
In particular:

€ Arrays with an interface type as the *component type* are allowed.
The
elements of such an array may have as their value a null reference or
instances of any type that implements the interface.
€ Arrays with an abstract class type as the *component type* are
allowed.
The elements of such an array may have as their value a null reference
or
instances of any subclass of the abstract class that is not itself
abstract.


When describing collections from the Collections framework there is
never any of this ambiguity/distinction - it is always "element type",
even when talking about a collection whose elements are themselves
collections.

Am I missing a "big idea"?

Any thoughts greatly appreciated.


Warning: I haven't read the latest JLS (I believe the one I read was for
Java 1.4), so I don't know if what changes there have been, but...

Arrays are treated specially in a lot of places in Java, and so some OO
purist recommend avoiding arrays altogether (and just using the ArrayList
class if you need array-like functionality). The syntax around arrays treat
them half like objects, half like primitive values. As far as I can recall,
only arrays have a "component type". So let me first start by definit
element type, and then I'll come back to "component type".

Collections are basically "a bunch of elements". The collection itself
has a type (e.g. "Vector", "ArrayList" , "HashMap", etc.), and the elements
it contains also has a type. In 1.4 and prior, that type was always Object,
but starting from 1.5, using generics, you could narrow down the type of
elements. For example, ArrayList<Integ er> has "Integer" as its element type.
ArrayList<TreeL ist<Comparable> > has TreeList<Compar able> as its element
type.

The parallel concept in array is "component type". The component type of
String[] is String. The component type of JTree[][][] is JTree[][]. The
*element* type of JTree[][][] is JTree. Confusing, yes, I know. They've
essentially swapped the meaning for "element type" between arrays and
collections.

Regarding this passage:
€ Arrays with an interface type as the *component type* are allowed.
The
elements of such an array may have as their value a null reference or
instances of any type that implements the interface.


Note that String is both the element type AND the component type of
String[]. So when they say "Arrays with an interface type as the component
type", that it equivalent (in all situations I could think of) of saying
"Arrays with an interface type as the element type".

However, there is a difference between "Arrays with an array as the
component type" and "Arrays with an array as the element type", with the
latter not making sense (the element type should never be an array).

I believe this strange naming system may be a "stuck" for backwards
compatibility reason. When you're using the reflections API, the class Array
has a method called getComponentTyp e(), and they could not rename, or change
its behaviour, without breaking existing code.

- Oliver
Jan 23 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
5161
by: ReignMan | last post by:
I'm running JDK 1.4.0_01, Xalan2.5.1 and Tomcat 4.1.27. XSL transformations work, yet when running in debug mode (Eclipse IDE), I get the following: 990S2html.xsl:3:80: Element type "xsl:stylesheet" must be declared. 990S2html.xsl:11:3: Element type "xsl:output" must be declared. 990S2html.xsl:12:25: Element type "xsl:template" must be declared.
0
2160
by: Leonardo Francalanci | last post by:
I wrote a function to sum arrays. It works, but I had to cast the data pointer to int64 (because my arrays are 'int8'): int64* ptr1 = ARR_DATA_PTR(v1); What if I want to write a more general function that adds values of 2 arrays of every int type? How could I do it? Here is the function (if you find any errors tell me...):
2
4112
by: Florian G. Pflug | last post by:
Hi Since sometime yesterday, my postgresql (7.4.5) reports "ERROR: cannot compare arrays of different element types", when I analyze a specific table in my database. Here is the tables definition: Column | Type | Modifiers -------------------+------------------------+---------------------------------------------------- self | datagraph."GOLink" | not null default
6
12770
by: libsfan01 | last post by:
hi all! is it possible to change an element type with javacript for example onclick to change a text box to a hidden element or to a textarea? kind regards marc
7
5127
by: Michael Bray | last post by:
Let's say I am using reflection to analyze my classes, and I have an array of another class. How do I get the base class that forms the array from a type? public class A { } A MyArray = new A;
3
4002
by: walex | last post by:
Hello guys, I'm trying to install devsec an application for ffpeg for camera,but on,is a c programme,after compilation ,i now type make, then this two error are generated.common.h:67: error: array type has incomplete element type common.h:71: error: array type has incomplete element type make: *** Error 1 make: Leaving directory `/root/devsec-3.0.6/ffmpeg/libavcodec' make: *** Error 2 make: Leaving directory `/root/devsec-3.0.6/ffmpeg'...
1
18342
by: shrav4ever | last post by:
Hi All, -------------------------------------------------------------------------------- This is a part of the code : -------------------------------------------------------------- extern struct dummy temp; error: array type has incomplete element type -------------------------------------------------------------- which i compiled without any error on : $gcc -v
1
1346
by: am72de | last post by:
Hi all, I have to write an editor for Visual Studio. It's one editor for different kind of Arrays: Button, TextBox and so on. The intern array is Control, so I can use it for all of the inherited controls. But now I don't know how to convert a Control back to the given type.
10
7634
by: arcadio | last post by:
Hi everyone, I'm currently struggling to compile a large piece of legacy code. GCC 3.3 compiles it without complaining, but GCC 4.2.3 (the default in Debian) refuses it and signals "several array has incomplete element type" errors. I know that since 4.0 or so, GCC is less forgiving and does not accept any arrays of incomplete type (see http://gcc.gnu.org/ml/gcc/2005-02/msg00053.html). However, I cannot see where the array types are...
0
8913
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9280
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9142
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8144
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.