A sintetic protected method could be created to invoke the GWT.create(this.getClass()):
public class A{ // created by the compiler protected void sintetic$create(){ GWT.create(A.class); }; public void foo(){ // replaced by the compiler sintetic$create(); } } public class B extends A{ // created by the compiler protected void sintetic$create(){ GWT.create(B.class); } } On Feb 16, 10:12 pm, Ray Cromwell <cromwell...@gmail.com> wrote: > But this.getClass() can be a polymorphic call not know until runtime. > > public class A { > public void foo() { > GWT.create(this.getClass()); > } > > } > > public class B extends A{} > public class C extends A{} > > A a0 = new A(); > A a1 = new B(); > A a2 = new C(); > > a0.foo(); // create(A.class) > a1.foo(); // create(B.class) > a2.foo(); // create(C.class) > > You can easily arrange it such that there's no way to statically > determine the type of 'this' > > -Ray > > On Tue, Feb 16, 2010 at 5:01 PM, Andrés Testi <andres.a.te...@gmail.com> > wrote: > > Done that this.getClass() is well known at compile time, could be a > > great improvement to adding support for GWT.create(this.getClass()). > > For example, Guice/GIN TypeLiteral<T> is not fully emulated in web > > mode because it's impossible to determine WTH is the type parameter T > > (not support for equals(), hashCode(), toString(), etc.) . With > > GWT.create(this.getClass()), TypeLiteral emulation could be defined > > as: > > > class TypeLiteral<T>{ > > > private final TypeInfo<T> typeInfo = GWT.create(this.getClass()); > > > protected TypeLiteral<T>(){} > > > public String toString(){ > > return typeInfo.toString(); > > } > > .... > > } > > > With such feature, the UiBinder boilerplate could be fixed: > > > class EasyUiBinder<U, O> implements UiBinder<U,O>{ > > private final UiBinder<U, O> impl = GWT.create(this.getClass()); > > > protected EasyUiBinder(){} > > > public U createAndBindUi(O owner) { > > return impl.createAndBindUi(owner); > > } > > } > > > UiBinder<Widget, EasyDemo> uiBinder = new EasyUiBinder<Widget, > > EasyDemo>(){}; > > > Are there technical limitations for support something like this? > > > - Andrés > > > -- > >http://groups.google.com/group/Google-Web-Toolkit-Contributors - Andrés -- http://groups.google.com/group/Google-Web-Toolkit-Contributors