I use Inline::Java to call a Java library from my Perl code. However, there is one function call I cannot get to work because it requires an enum type as argument.
These are my Java method signatures:
public class Initializer {
[...]
public int initializeExtractor() {...}
public int initializeExtractor(Language... languages) {...}
I am trying to call the latter version in Perl:
use Inline (
Java => 'STUDY',
[...]
AUTOSTUDY => 1,
STUDY => [
[...],
'package.Language'
],
JNI => 0,
);
[...]
my $instance = package::Initializer->new( $self->directory() );
$instance->initializeExtractor($package::Language::ENGLISH);
This is the error message:
In method initializeExtractor of class package::Initializer: Can't find any signature that matches the arguments passed (package::Language=HASH(0x2328708)).
Available signatures are:
initializeExtractor([Lpackage.Language;)
error was: package.Language is not a kind of [Lpackage.Language; at /usr/local/lib/perl5/site_perl/5.22.4/x86_64-linux-thread-multi/Inline/Java/Object.pm line 107.
initializeExtractor()
error was: Wrong number of arguments at /usr/local/lib/perl5/site_perl/5.22.4/x86_64-linux-thread-multi/Inline/Java/Object.pm line 107. at /.../PP.pm line 57.
Calling the first method (initializeExtractor(), without arguments) works such fine which is why I am pretty sure my 'studies' are fine.
However, according to this thread, I think I do access the Java enum in the right way.
The fact that the Java method has a varargs arguments seems not related to me, is it?
The error message seems a bit misleading because it looks like the first reported available signature matches exactly the argument that I pass.
The varargs argument is related to you. The declaration public int initializeExtractor(Language... languages) {...} defines a method that expects an Array of Language objects, but provides syntactic sugar so that a Java call with a single Language argument is coerced into an Array with one element, but it looks like the Inline::Java package in Perl has not been sweetened this way:
package.Language is not a kind of [Lpackage.Language;
i.e., a single package.Language argument is not the same thing as a list of package.Language objects. You can explicitly provide the list from Perl but enclosing the argument in [brackets].
$instance->initializeExtractor( [ $package::Language::ENGLISH ] );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With