1

The for..of syntax has been introduced in ES6.

It's supposed to be supported since JDK9 as part of JEP 292.

However, when I run OpenJDK 10's jjs, I get an exception:

jjs> for (var foo of ['bar', 'baz']) { print(foo); }
ECMAScript Exception: SyntaxError: <shell>:1:13 Expected ; but found of
for (var foo of ['bar', 'baz']) { print(foo); }
             ^

1 Answer 1

2

By default jjs supports ECMAScript 5, this can be fixed by running jjs with the flag --language=es6 at least with Java 9.

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

2 Comments

Nice example of a self-answer. You could improve this, by adding a link to the documentation (if it exists), or an explanation how you figured this out, in case someone runs into a similar but not identical problem.
@JörgWMittag Good idea, done! I wanted to provide in my question the exact versions I was running and went to check jjs' documentation. That's where I found my answer :)

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.