Export to GitHub

google-web-toolkit - issue #695

ArrayList toArray(SomeClass[]) should be implemented


Posted on Feb 14, 2007 by Grumpy Horse

Found in GWT Release: 1.3

Detailed description: The toArray(SomeClass[]) method is not implemented in GWT's ArrayList. At the very least the documentation should clearly state that the method is not available because it is a widely used method on java.util.ArrayList.

Workaround if you have one: Write your own implementation of

static MyClass[] toArray(List/<MyClass>/ list)

for each class you need to do this for.

Links to the relevant GWT Developer Forum posts: http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/f46ac6677ffa85c0/a9d911421f528778?lnk=gst&q=toArray&rnum=1#a9d911421f528778

Comment #1

Posted on Feb 15, 2007 by Happy Bird

(No comment was entered for this change.)

Comment #2

Posted on Apr 29, 2007 by Massive Monkey

This method is nice for eliminating casting and copying, e.g.

HasFocus[] result = new HasFocus[list.size()]; list.toArray(result); foo(result);

vs

HasFocus[] result = new HasFocus[list.size()]; Object[] temp = list.toArray(); for (int i; i < result.length; i++) { result[i] = (HasFocus) temp[i]; } foo(result);

I realize that without refelection you cannot auto-expand the array parameter's size. But even a minimal implementation which throws an IndexOutOfBoundsException would save a lot of user code. (I wonder if you really need reflection. How are arrays implemented in GWT? Could JSNI be used to expand the size of the array param?)

Comment #3

Posted on Jul 19, 2007 by Quick Ox

+100 for this one.

I tried to use toArray( Range[ result.size() ] ) but the compiler fails to run in this case.

If I just use toArray() then in the browser it works but the Hosted mode fails because of a ClassCastException. Using GWT.isScript does not help unfortunately.

Comment #4

Posted on Jul 19, 2007 by Swift Hippo

This kind of fell off the radar.

Comment #5

Posted on Aug 3, 2007 by Swift Hippo

Committed as r1270.

Comment #6

Posted on Aug 20, 2007 by Swift Hippo

1.4 RC2 now released.

Comment #7

Posted on Feb 25, 2008 by Helpful Dog

When inspecting the JClassType of the interface java.util.List it does not have a JMethod for the interfaces method "toArray(Object[])". Should this not be available? I'm writing a generator that creates a class that implements java.util.List, I loop through all the methods, however the generated class fails to compile indicating:

The type ListWrapper must implement the inherited abstract method Collection.toArray (Object[])

Comment #8

Posted on Apr 28, 2008 by Grumpy Horse

Comment #9

Posted on Apr 29, 2008 by Quick Kangaroo

Comment #10

Posted on Apr 29, 2008 by Quick Kangaroo

Comment #11

Posted on Apr 29, 2008 by Quick Kangaroo

Comment #12

Posted on Feb 9, 2011 by Swift Ox

(No comment was entered for this change.)

Status: Fixed

Labels:
Type-Enhancement Priority-Medium Category-JRE ReviewBy-knorton Milestone-1_4-RC2