This is the mail archive of the java-patches@sources.redhat.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Patch: Xlib AWT and Java 2D


Jeff Sturm wrote:

> Breaking encapsulation that way should not be necessary in general... the
> compiler can inline the necessary calls.  Unfortunately in this case
> getX/getY/etc. are not declared final (as they ought to be if the member
> variables are not private and thus probably cannot be overridden in a useful
> way).

The member variables are all package-private.

It is true that a good compiler should inline virtual methods to some extent,
but not without at least some runtime overhead (ie a branch based on the results
of a type test)

The reason I think it is safe to bypass the get methods is that it is what Sun's
implementation does. If you extend component and override getX, getBounds, etc,
and put in a Thread.dumpStack(), the only times these methods ever get called is
from other packages (eg sun.awt):

getBounds
java.lang.Exception: Stack trace
        at java.lang.Throwable.<init>(Throwable.java:96)
        at java.lang.Exception.<init>(Exception.java:44)
        at java.lang.Thread.dumpStack(Thread.java:1007)
        at MyComponent.getBounds(CmpTest.java:19)
        at
sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:39)
        at
sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:91)
        at java.awt.Container.paint(Container.java:968)
        at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:26)

        at sun.awt.RepaintArea.paint(RepaintArea.java:309)
        at sun.awt.motif.MComponentPeer.handleEvent(MComponentPeer.java:348)
        at java.awt.Component.dispatchEventImpl(Component.java:2701)
[...]

Presumably, component writers are not supposed to override the get methods
without calling super.

regards

  [ bryce ]



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]