Stupid Newbie Java Question

Status
Not open for further replies.

Dandy Andy

Ars Tribunus Militum
2,458
Yep, arrays use "arrayName.length" which is a bit of anomoly, (since its not arrayName.length() or something), but I'm sure it makes sense to someone.

Doesn't this just imply that arrayName.length is an instance variable rather than a method? This also implies that the object arrayName keeps it's element count up-to-date internally and makes it available as "length", rather than having to recalculate it via a method. Whatever methods are provided to add or remove elements must update "length" during execution. The upside of this is that you don't have the processing overhead of invoking a method to get the count, and therefore won't be tempted to cache this value in a local variable (and forget to resynchronise it with "reality" when you add or remove elements).

Oh not; I'm a Java noob as much as the next person.

;)
 

Midlands

Ars Praetorian
535
Subscriptor
The problem with it being a pseudo-field is that there's no such thing as a read-only field in Java, so then 'foo.length = 15' would have to be valid for it to remain internally consistent. A function would be better.

As for istream/ostream << and >> operators, I say, hmph. Overriding bitshift operators to do I/O is just a bad idea, period.

Java does have fairly crappy string I/O handling, in general -- honestly, printf() does have its problems, but it's damned useful in so many ways -- but most people don't write console I/O programs in Java, so it doesn't really matter. I write big honkin' servers in Java, so, to me, the fact that AWT, Swing, and text I/O are all one big pile of junk in Java doesn't matter much.
 
Status
Not open for further replies.