Jimmy Talbot wrote:
Hi,Hi Jimmy,This is more a general java programming question, but here goes:
The 'const' keyword in C++ is really useful, as it allows the compiler to
make some serious optimizations and helps detect bugs at compile-time.The more-or-less Java equivalent is 'final'. Yet, in almost all the
examples that I see, 'final' is nowhere to be found. Why? Doesn't the
compiler do any optimization with 'final' objects?Thanks
Jimmy
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".
Good question.
What const is realy useful for in C++ is specifying parameters as const reference or rather 'reference to const objects'. This means that the method isn't able to change the value of that object. But without sacrificing performance - in contrast to using value parameters. To the user of the method the const reference is very important information - meaning this method can safely be used without worrying that it will change the users object,
Java is different.
All parameters in java are values and all objects are realy handles (sort of reference) to objects. That means, when you give an object as parameter to a method: what is transferred is the value (copy) of the handle (in most cases a memory address). If you specify a parameter as a final object, it is the local copy of the handle which is final, not the object behind it - you can still change the object via it's public methods and variables.
The conclusion is: 'final objects' in java doesn't exists. I think it's a big miss. The only way to tell the programmer, if a method changes objects, is through documentation. And to make things even worser: very few programmers tells about this in the documentation - java3d doesn't, I think. And furthermore this is a really a big design issue, when making librarys: Shall the library make copies of objects it receives or shall that be leaved to the users of the library. The first solution is the safe one, while the last is optimal for performance. I have been told java3d has changed philosophi at that point from saving copies in the library to just saving handles to the users object - very dangerous thing to change.
Sorry for the long answer, but you hit the point, where java has disappointed me the most, having programmed in C++ for about 12 years - else I like java very much. I would realy like to hear other opinions on this theme.kind regards
Hardy Henneberg