Hi Dean,
thank you for your answer.
I have tried that out and I get exactly the same behaviour as you have
descriebed.

The above error occured to me in a composite that is the super class
of all my composites. I have enhanced your sample classes to
demonstrate it:

public class ClassA extends Composite {
        private String name;

        public ClassA(String name) {
                this.name = name;
        }

        protected void initWidget(Widget w) {
                super.initWidget(w);
                doThat();
        }

        private void doThat() {
                Window.alert("A here " + this.name);
        }
}


public class ClassB extends ClassA {
        private String name;
        private DockPanel layout = new Dockpanel();
        public ClassB(String name) {
                super(name + " from B");
                this.name = name;
                initWidget(layout);
        }

        public void doThat() {
                Window.alert("B here " + this.name);
        }
}

The error only occured in Firefox. I have fixed it by not calling the
doThat() method in ClassA. I have put its content directly into the
initWidget() method.

Regards
Andreas

On 6 Jun., 07:50, "Dean S. Jones" <[email protected]> wrote:
> Not happening here at all... One issue is you B's ctor will call your
> A's ctor, which ill run A's doRead()...
>
> check this code:
>
> ublic class A {
>
>         private String name;
>
>         public A(String name)
>         {
>                 this.name = name;
>
>                 doThat();
>         }
>
>         private void doThat()
>         {
>                 Window.alert("A here " + this.name);
>         }
>
> }
>
> public class B extends A {
>
>         private String name;
>
>         public B(String name)
>         {
>                 super(name + " from B");
>
>                 this.name = name;
>
>                 doThat();
>         }
>
>         public void doThat()
>         {
>                 Window.alert("B here " + this.name);
>         }
>
> }
>
> then
>
> A a = new A("Hi");
> B b = new B("Bye");
>
> b.doThat();
>
> my ( expected, and actual ) output in hosted and compiled mode is:
>
> "A here Hi" ( A's ctor calls it's private method )
>
> "A here Bye from B" ( B's ctor calls A's ctor, A's ctor calls it's
> private method )
> "B here Bye" ( B's ctor calls it's method )
> "B here Bye" ( direct call to B's method )
>
> Do you get something different???
>
> You should avoid calling potentially overridden methods in
> constructors. Java ( unlike C++ ) will happily call a sub-classes
> method, which might be
> dangerous as the chain of construction is incomplete. That doesn't
> LOOK like your problem tho...
>
> On Jun 5, 5:41 am, andi <[email protected]> wrote:
>
> > Hi all,
>
> > I have encountered a trap between java and javascript.
>
> > In Java I can do this:
>
> > ClassA{
> >      public ClassA() {
> >          doRead();
> >      }
>
> >     private int doRead();
>
> > }
>
> > ClassB extends ClassA{
> >     protected int doRead();
>
> > }
>
> > If I call doRead() of ClassB then doRead() of ClassB is executed. If I
> > call the constructor new ClassB(), doRead() of ClassA is executed. So
> > in Java these two methods are completely different and independent
> > from each other.
>
> > I found out that in the compiled JavaScript code the doRead() method
> > of ClassB overwrites the method of ClassA and would be called in the
> > constructor call.
>
> > What do you think about this issue?
>
> > Best regards
> > Andi

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to