Sorry, I should have given a more detailed explanation. Here's what
happens:
Let's say I have two classes:
public abstract class A {
public void method();
}
public abstract class B extends A {
public void stuff() {
}
// ...
}
In my module I have the following rule:
<generate-with class="com.test.rebind.AGenerator">
<when-type-assignable class="com.test.client.A" />
</generate-with>
Then I generate the class:
B b = GWT.create(B.class);
Which generates the following code:
public class generated_B {
public void method() {
// implementation
}
}
The above compiles without problems in hosted mode. When I try to
compile in web mode however, I get "Rebind result "com.test.client.B"
cannot be abstract". If I were to make A a non-abstract class and
implement A.method() and try to invoke B.method(), which should call
generated_B.method(), A.method() is called instead. I inspected the js
output verified that A.method() is called on generated_B even though
generated_B is instantiated as desired.
>From what I can see, the js compiler creates global functions for
every method, so A.method() would be transformed into A_method
(instanceOfA). So even though polymorphism works as expected in hosted
mode the js compiler doesn't seem to track type information in that
particular case.
On Oct 28, 6:30 pm, Thomas Broyer <[email protected]> wrote:
> On 28 oct, 13:03, q2dm1 <[email protected]> wrote:
>
> > Hi,
>
> > I'm trying to instantiate an abstract class with GWT.create(), however
> > the compiler tells me that rebind results can't be abstract. Is there
> > an explanation for this? If rebind results can be interfaces, why not
> > abstract classes?
>
> You're missing a <generate-with> or <replace-with> deferred-binding
> rule in your module(s) to generate/"redirect" to a non-abstract,
> "default instantiable" class.
> When no <generate-with> or <replace-with> rule match, GWT.create()
> uses a "new TheClass()" as a last resort, so it has to be concrete
> (non-abstract).
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---