|
I've read with interest about the necessity of type casting here:
http://search.cpan.org/~patl/Inline-Java-0.52/Java.pod#TYPE_CASTING
I am trying to apply the same recipe to traverse a collection returned by WWW::HtmlUnit but casting did not help. The problem lies in accessing a private inner class through an Inline::Java link. In fact the error I get is:
You are not allowed to invoke method toArray in class java.util.Collections$UnmodifiableRandomAcces
+sList: Class InlineJavaUserClassLink can not access a member of class java.util.Collections$Unmodi
+fiableCollection with modifiers "public"
Found below a bit of code to reproduce my problem. Is there any fix for that or an alternative way to implement something like the Java enhanced for loop with Inline::Java?
use WWW::HtmlUnit;
use Inline::Java 'cast';
my $browser = WWW::HtmlUnit->new();
my $page = $browser->getPage( 'http://google.com/search?q=God' );
my $table = $page->getHtmlElementById('nav');
my $rows;
# Here I get the above error...
$rows = $table->getRows( )->toArray;
# This does not work either. I think because UnmodifiableRandomAccessList
# is defined as a private (not public) inner class of java.util.Collections.
$rows = cast('java.util.Collections$UnmodifiableList', $table->getRows( ))->toArray;
|