File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -383,6 +383,27 @@ In both JRuby and TruffleRuby you call Java methods as you would a Ruby method.
383
383
JRuby will rewrite method names such as ` my_method ` to the Java convention of ` myMethod ` , and convert ` getFoo ` to ` foo ` , and ` setFoo ` to ` foo= ` .
384
384
TruffleRuby does not perform these conversions.
385
385
386
+ ### Calling Overloaded Method
387
+
388
+ When multiple overloads are possible, it needs to be selected explicitly.
389
+ For instance ` java.util.concurrent.ExecutorService ` has both ` submit(Runnable) ` and ` submit(Callable<T> task) ` .
390
+ Calling submit without specifying which one shows the possible overloads:
391
+ ```
392
+ $ ruby -e 'Java.type("java.util.concurrent.Executors").newFixedThreadPool(1).submit {}'
393
+ -e:1:in `main': Multiple applicable overloads found for method name submit (candidates: [
394
+ Method[public java.util.concurrent.Future java.util.concurrent.AbstractExecutorService.submit(java.util.concurrent.Callable)],
395
+ Method[public java.util.concurrent.Future java.util.concurrent.AbstractExecutorService.submit(java.lang.Runnable)]],
396
+ arguments: [RubyProc@4893b344 (RubyProc)]) (TypeError)
397
+ ```
398
+
399
+ You can select a specific overload using:
400
+ ``` ruby
401
+ executor = Java .type(" java.util.concurrent.Executors" ).newFixedThreadPool(1 )
402
+ executor[' submit(java.lang.Runnable)' ].call(-> { 1 })
403
+ # or
404
+ executor.send(" submit(java.lang.Runnable)" ) { 1 }
405
+ ```
406
+
386
407
### Referring to Constants
387
408
388
409
In JRuby, Java constants are modelled as Ruby constants, ` MyClass::FOO ` .
You can’t perform that action at this time.
0 commit comments