Olivier Lefevre wrote:
It is made final to lock in its implementation since internal code
relies on its internal structure.

Eh? That could be said of almost any class with internal state.

In some cases, for efficiency, code outside of the class can go inside
its internal representation and get answers without calling the public
methods.  In this case, native code can access the array of coordinates
directly without having to do upcalls to the Java methods to get the
geometry and the performance is much improved.

If the class were not final then there would be a danger that someone
might have subclassed it and be returning different information from the
methods which conflicts with the information one might assume from the
internal data structures.  To prevent that contradiction the class (or
the associated methods) are made final.

Most classes with internal state are accessed through their methods
exclusively so they don't have this potential problem.

A real world case where the lack of "final" may be hurting us is
Color.createContext().  It was not made final because of historical
issues with how SystemColor was implemented.  A lot of code internally
sees a Color object and immediately knows how to perform the operation.
 Unfortunately, some developers consider that since createContext() is
not final, then they can subclass it and override createContext() to
return, say, the context of a GradientPaint and then turn a Color into a
gradient.  Unfortunately this fails whenever code does "instanceof
Color" and then takes an optimal Color-specific path which never calls
the createContext() method.  It's almost worth retroactively making the
method final (as of 1.6 it now no longer needs to be subclassed in
SystemColor any more), but that would break binary compatibility...

                       ...jim

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to