List or ArrayList/concrete type

565 views
Skip to first unread message

tanteanni

unread,
Jan 26, 2012, 7:58:14 AM1/26/12
to google-we...@googlegroups.com
at the beginning of my gwt adventure i read somewhere that it is better to use concrete classes for interfaces like lists, because the gwt compiler must generate java script for every kind of list.
Is this (still) true? I asked because by using arraylist/concrete types everywhere on client side yields a lot of "loose coupling" warnings from sonar and beside this it is the absolute opposite of the make-(gwt)-code-more-testable-by-using-interfaces-as-much-as-possible-philosophy.

thx in advance

Thomas Broyer

unread,
Jan 26, 2012, 8:57:33 AM1/26/12
to google-we...@googlegroups.com


On Thursday, January 26, 2012 1:58:14 PM UTC+1, tanteanni wrote:
at the beginning of my gwt adventure i read somewhere that it is better to use concrete classes for interfaces like lists, because the gwt compiler must generate java script for every kind of list.
Is this (still) true?

Only on GWT-RPC, and yes it's still true. If you say you're transferring SomeObject via RPC, GWT has to compile the code for every class it knows that extends SomeObject, so you can safely send and receive SomeOtherObject (provided "class SomeOtherObject extends SomeObject"). So if you say java.util.List, GWT will grab java.util.Collections.SingletonList, java.util.Collections.EmptyList, java.util.Collections.ImmutableList, java.util.Arrays.ArrayList, java.util.ArrayList, java.util.LinkedList, etc. whereas if you say java.util.ArrayList, it reduces the number of classes that you app has to know about.

You can safely use java.util.List everywhere else in your code, just not in your method declarations in your GWT-RPC interfaces.

BTW, AutoBeans and RequestFactory only allow java.util.List and java.util.Set (and java.util.Map for AutoBeans), not java.util.ArrayList, java.util.HashSet or java.util.HashMap for instance.

Thomas Broyer

unread,
Jan 26, 2012, 9:00:43 AM1/26/12
to google-we...@googlegroups.com
I forgot to mention that this is documented at: http://code.google.com/webtoolkit/doc/latest/DevGuideServerCommunication.html#DevGuideSerializableTypes (section "polymorphism")

tanteanni

unread,
Jan 26, 2012, 9:47:02 AM1/26/12
to google-we...@googlegroups.com
thx for the info,

that means i can get rid of most of "loose coupling" -warnings (i thought all client code should avoid "Lists"s - ).

Hua Zhang

unread,
Dec 4, 2022, 6:30:16 AM12/4/22
to GWT Users
Is this 'concrete type' als valid for a DTO object in GWT-RPC?

For example, I have a TestDTO object, which needs to be transferred via GWT-RPC.

public class TestDTO implements IsSerializable {
        public ArrayList<String> data;

        public List<String> operation() {
                return null;
        }
}

If I understand correctly, data field needs to be a concrete type. How about the method operation, can I return here a generic List interface?

Best regards,

Hua
Reply all
Reply to author
Forward
0 new messages