On 23 fév, 18:37, Ian Petersen <[email protected]> wrote:
>
> > Any widget (any class) with a zero-arg constructor can be instantiated
> > with GWT.create(), though I wouldn't recommend doing it (see my advice
> > to Eugen).
>
> Why would you use GWT.create(Foo.class) in the instances that it's
> equivalent to new Foo()? GWT.create() is really only useful in two
> cases: you want to choose a class' implementation based on some
> runtime constant (user agent, locale, etc.) at compile time or you
> want to generate an implementation based on compile time knowledge
> (RPC implementations, data binding, image clustering etc.). In any
> situation that is equivalent to invoking a no-args constructor of the
> type specified as a parameter to GWT.create(), using GWT.create()
> instead of just invoking the constructor does nothing more than
> obfuscate your code.
As I said: I wouldn't recommend it, but it works.
> I'll admit I didn't realize you could make use of this obfuscation
> technique, but, having written a fair number of lines of code that are
> invoked by GWT.create(), I think it's a special case that can be
> safely ignored most of the time.
>
> I'd be curious for a GWT dev to explain why GWT.create(Foo.class) even
> degenerates to new Foo() in the absence of a rule for that case.
It saves you a rule definition?
If it weren't that way, everyone would use a catch-all rule without
condition.
> It seems to me that should be a compile-time error.
If Foo is not instantiable (abstract class or interface), you'll have
one.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---