GWT JavaScriptObject overloading generic fails
I attempted to ov开发者_C百科erload List with a list that handles JavaScriptObjects
public class JsList<T extends JavaScriptObject> extends JavaScriptObject implements List<T>
{ etc...}
which works fine when compiled to javascript but fails in hosted mode as well as the Designer. The issue stems from
CompilingClassLoader::findOverloadUsingErasure(JClassType implementingType, JMethod intfMethod)
when the function tries to find the overloaded function, it fails because the type T of JsList equates through erasure to JavaScriptObject and the type T of List equates to Object. Any suggestions on a fix for this?
Given that an interface can be implemented by at most one JSO, how about removing the bounds of your type variable?
The alternative would be wrap the JSO into an object implementing List, rather than have the JSO implement the interface itself.
AS a side note, remember that the Java List
has more constraints than a JS array. For instance, you can do in JS:
var arr = [];
// arr.length is 0
arr[3] = "foo";
// arr.length is now 4
arr.length = 2;
// arr.length is now 2
// arr[3] can be retrieved but is 'undefined'
Which you cannot do in Java:
List<String> list = new ArrayList<String>();
// list.size() is 0
list.put(3, "foo"); // ← throws an IndexOutOfBoundsException
// list.get(3) would throw too
精彩评论