On 19/08/11 08:07, David wrote:
but in my applicaiton:
public Map <java.lang.String,java.util.List> filterStates = new HashMap();
the value of filterStates is java.util.List, I can't specify the type for it,
for in my app, this value is Object, it might be String, and other self-defined
class/object, how to handle this?
In that case, your compile will take longer and generate more javascript so
your app will be slower to start for users than it need be. Methods for making
this kind of thing work better include:
(1) Define an interface (or a base class) and have all classes you want in your
list implement that interface. You can't do this directly with String because
it's a final class. You can, however, create a wrapper class around String.
Something like:
public interface State {}
public class StringState implements Serializable, State { String state; }
and then you have:
Map<String, List<State>> filterStates = new HashMap<String, List<State>>();
(2) Create a class that holds an instance of each type you might want to send,
and give it an extra property that says what type of thing it contains:
public enum MyType {STRING, FOO, BAR }
public class State implements Serializable {
MyType type;
String string;
FOO foo;
BAR bar;
}
If you really don't know whether there's a String or some other object in your
list, then it may be that you object model should be changed anyway. Otherwise
you'll probably end up with lots of code like:
List list = ...;
for (Object o : list) {
if (o instanceof String) {
// do something with String
} else if (o instanceof Foo) {
// do something with Foo
}
}
HTH
Paul
--
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-toolkit@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.