I can not really recreate the issue, because I am using Java 1.7 (you
are doing it with Java 1.8, aren’t you?), and it seams that 1.7 doesn’t
have the method ‘stream’ yet, because I get the error message
However, I see a few other suspicious points in your code:
You are applying the method ‘limit’ to the result of ‘map’. I am not
aware of the existence of this method, and could not find it in the core
docs. Could it be that you mean ‘take’ instead?
The error message says
“wrong number of arguments (1 for 2)”
which means “you supplied to 1 argument, but two where expected”. Your
call to collect looks like
collect(l1,l2,l3)
which passes 3 arguments. The Java version of ‘collect’ expects 3
arguments, but from the error message, we conclude not only, that a
different ‘collect’ is executed from what you expect, but it is also
weird that a different number of arguments is reported. So I ask my
self: Can you verify, that this is really THIS collect call, which is in
error, and not a different one in some other part of your program? Can
you reproduce this error with the code given, in jirb?
If yes, maybe you could print out the class name of the result of your
limits() call, to see whether this is really the class you are
expecting.
l1, l2, l3
ArgumentError: wrong number of arguments (1 for 2)
from org/jruby/java/proxies/JavaProxy.java:352:in java_send' from (irb):24:in’
from org/jruby/RubyKernel.java:978:in eval' from org/jruby/RubyKernel.java:1291:inloop’
from org/jruby/RubyKernel.java:1098:in catch' from org/jruby/RubyKernel.java:1098:incatch’
from C:/languages/jruby/jruby-9.0.4.0/bin/jirb:13:in `’
OK, so the problem is not the invocation of ‘collect’, but something
which happens inside ‘collect’, which means that, if the error is in
your code, it must be in one of your lambda definitions. Now this is an
area I don’t know much about, and I don’t know enought about the Java
code, but the error message says that two arguments are passed to a
method, where only one is expected.
In your code, I can’t see any function where you explicitly pass two
arguments, so just a wild guess:
‘collect’ is defined on the Java side, expecting Java-Lambdas, and you
are passing it Ruby-Lambdas. Could it be, that this conversion doesn’t
work right yet in JRuby?
What happens, if you directly execute
number.stream.collect(…)
? If this brings up the same error message, I suspect that this is a bug
in JRuby and you could open a bug report for it.