2

Quick question here -- I just used JsArrayString for the first time, and was surprised that this didn't work:

JsArrayString object = ...;
for (String s : object)

So I just wrote a C-style for loop:

JsArrayString object = ...;
for (int i=0; i<object.length(); i++) {
    s = object.get(i)
    ...

Not a big deal, but seems like it would have been simple for the GWT team to have JSArrayString implement iterable, so I wanted to check and make sure I wasn't missing something...

2 Answers 2

4

I suspect it's a matter of code bloat and for that matter code size. If they make JsArray implement Iterable, it might open the door for other additions that wouldn't always be useful. JsArrays are meant to be absolutely as simple and barebones as possible.

Additionally, you could write your own JsIterable class that does this if you want this behavior, as you said it should be pretty trivial to implement.

The Lightweight Collections design doc addresses some of the issues around using JRE collections and related concepts and discusses which features could be left unsupported to ensure absolute minimum code size, including:

Until the GWT compiler can optimize it (which it cannot to date), the new collections will not support the Java enhanced 'for' loop syntax that uses Iterable/Iterator. We do believe such optimizations are possible and will be added, however, at which time, these collections will be retrofitted to implement Iterable.

Sign up to request clarification or add additional context in comments.

Comments

0

You have to do it the old-school way :). Check out the source of it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.