Unable to iterate over Java object properties using for (var p in object) construct

A. Sundararajan sundararajan.athijegannathan at oracle.com
Mon Mar 10 03:12:55 UTC 2014


Iterating properties of java objects - both fields, methods - is a rhino 
specific feature. This is not supported by nashorn. If you've a java 
array or Iterable, JS for and for..each will do the expected - namely 
iterate over the array/collection.

Thanks
-Sundar


On Sunday 09 March 2014 02:55 AM, Walter Higgins wrote:
> In Java 7 I can iterate over the properties/methods of a Java object using
> this notation...
>
> for (var p in javaObject) {
>    print(p);
> }
>
> In java 8 this no longer works.
>
> for (var p in javaObject) {
>    print(p);
> }
>
> ...doesn't result in the for loop block being executed (there are no
> properties).
>
> How can I iterate over the Java object properties in a consisted way
> between Java 6, 7 and 8?
>



More information about the nashorn-dev mailing list