Sunday, March 27, 2011

JavaScriptObject array for Java Objects

In my app I use JsArray extensively to store my overlays. I use
java.util.List to store my client-side Java POJOs.

For performance reasons and to unify the way I access my model I
planned to eliminate the Lists and use only JSO wrappers. Given a
wrapper around a native array that can store any Java Object:

public class JsArrayObject<T> extends JavaScriptObject {

protected JsArrayObject() {}

public final native T get(int index) /*-{
return this[index];
}-*/;

public final native void push(T value) /*-{
this[this.length] = value;
}-*/;

}

Is it safe to store Java Objects this way? The doc says that when you
pass a Java Object into JavaScript the result is "an opaque value
accessible through special syntax". This sounds confussing to me. For
instance if I push an Integer and try to get it an exception will be
thrown because something different than an Object was found (at least
in dev mode). The same happens with the rest of Java primitive
Wrappers. Apart from the problems with Java primitive Wrappers, are
there other concerns to be aware?

Many thanks

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment