Thank you for the reply I did not know much about GWT-RPC, bay be I should study more before making questions... I was aware of the generic call, but looks to me like a cast :)
I was NOT aware of the feature called 'type inference'. I used my IDE to complete, and noticed that only Object methods were allowed chained after a GWT.create(), so I thought that I needed a cast to assign to a variable. Now I readed the java tutorial on Generic Methods and everything looks much more consistent... I knew about generic methods, but missing the type inference I always wondered what were they useful to... :) On 28 Nov, 10:56, Thomas Broyer <t.bro...@gmail.com> wrote: > On 26 nov, 21:12, "Alessandro Carraro (JUG Padova)" > > <carraro.alessan...@gmail.com> wrote: > > A simple qestion, sorry if it is a FAQ: > > > Why > > public static <T> T create(Class<?> classLiteral) > > and not > > public static <T> T create(Class<T> classLiteral) > > With GWT-RPC you pass the "synchronous" (extends RemoteService) > interface as an argument and it returns an implementation of the > "asynchronous" interface. > That wouldn't be possible with the Class<T> argument. > > > the second one would save me from a lot of unnecessary casts (IMHO). > > I hardly ever needed a cast: > - either the GWT.create() result is assigned to a variable, and javac/ > GWT compiler is smart enough to infer the generic type argument > - or if it's not possible, you can use a "generic call" instead of a > cast: GWT.<MyClass>create(...) but I admit it adds the same > boilerplate as a cast... > > > What's worse, I tried to write the helper function: > > > @SuppressWarnings("unchecked") > > public static <T> T create(Class<T> classLiteral) { > > return (T) GWT.create(classLiteral); > > } > > > But after a month I discovered that the compiler does not like it at > > all (it complains that GWT.create must be called only using class > > literals... could be nice if it could find that MY helper is called > > with only using literals... > > It's been requested several types in the past (including by people > that now work at Google on GWT) but I guess it's either low priority > or it would require too much re-work of the compiler's internals. > > > Is it possible to get a hook into the compiler phase to replace all > > invocations of my helper 'inlining' it? > > I don't think so; but is it really worth it? risking bugs in your > "hook" just to save you from typing a few characters (that, moreover, > any good IDE is capable of generating for you) -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to google-web-tool...@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.