[3296] in java-interest

home help back first fref pref prev next nref lref last post

Re: arrays of instances of objects

daemon@ATHENA.MIT.EDU (Thomas Ball)
Mon Nov 6 18:37:38 1995

Date: Mon, 6 Nov 1995 12:02:48 -0800
From: Thomas.Ball@Eng.Sun.COM (Thomas Ball)
To: nrc2@aber.ac.uk
Cc: java-interest@java.Eng.Sun.COM

That's right, you still need to initialize it -- this bit me hard when
I first started using Java, and it should be documented better.  Since
Java doesn't support the notion of a default constructor, the array
allocator has no way of knowing what constructor to call.

It may seem a bother to have to explicitly initialize each member, but
one of the design principles of Java was to reduce most of C++'s hidden
behaviors in favor of explicit statements.  Even if you don't like that
approach, the engineer after you who has to support your code probably 
will.

Tom Ball
Java Products Group

----- Begin Included Message -----

From daemon@java  Mon Nov  6 06:35:38 1995
To: java-interest@java
Subject: arrays of instances of objects
X-Info: To unsubscribe, send 'unsubscribe' to java-interest-request@java.sun.com

I'm having trouble defining an array of instances of objects

I have a class called TreeNode that is a node of a Binary Tree and I
want to declare an array of instances of this.  I've tried

TreeNode Tree[] = new TreeNode[16];

but this seems to declare an array of null pointers.

Thanks.

Neil
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com


----- End Included Message -----


-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post