Take the 2-minute tour ×

There are already a few questions regarding the fact that methods in GWT RPC should not return an interface like List, but rather a concrete class like ArrayList, because otherwise "GWT needs to include all possible implementations". See e.g. In GWT, why shouldn't a method return an interface?

Here's my question: is this limited to the return type itself? How about parameters of the method? And what if the return object contains an interface, e.g.

public class MyReturnObject implements IsSerializable {
   List<String> listOfUnspecifiedType1;
   List<Long> listOfUnspecifiedType2;

The examples I have seen all talk of the return type itself. I don't see why it would be a problem to return an interface, but not a problem to return an object which just wraps an interface; but maybe I am missing something?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

It's clear from the linked question that it applies recursively (and as soon as you understand why you should use the most derived types as possible, it becomes obvious that it is recursive).

This is also true of method arguments, not only the return types and their fields: if you send a List<X> then GWT has to generate serialization code for all List classes: ArrayList, LinkedList, etc.

And of course the same applies to classes, not only interfaces: AbstractList is no different from List.

And because generation comes before optimization, all possible classes from the source path will be included, not only those that you use in your code; and then they come in the way of the optimization pass, as all those classes are now used by your app.

Therefore, the rule is: use the most specific types as possible. The corollary is: don't fear DTOs, don't try to send your business/domain objects at all cost.

share|improve this answer
Thanks… It does make sense, I just wanted to make sure. –  user711413 Jan 16 '13 at 21:21
add comment

Your Answer


