Creates an instance of the specified Java interface (or interfaces if an array is used) backed by the specified closure.
^Class - the class to create an instance of (limited to Java interfaces for now)
@array - an array of Java classes to create an instance of
&closure - the closure to back this proxy Java object with.
an instance of a Java object that implements the specified interfaces.
@list = @("a", "b", "c", "d", "e"); sub iterator { if ($0 eq "hasNext") { return size(@data); } if ($0 eq "next") { return shift(@data); } } $iter = newInstance(^java.util.Iterator, lambda(&iterator, @data => @list)); while ([$iter hasNext]) { $element = [$iter next]; println($element); }
a b c d e