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
-~----------~----~----~----~------~----~------~--~---