1

I need my JRuby method to recieve a report of what is going on in a Java method and act accordingly:

def my_long_running_method
  # ... do stuff ...

  jObject.count_all_disk_files do |number_of_files|
    stream.write "#{number_of_files} files found so far."
  end

  # ... do more stuff ...
end

I saw this question but I couldn't understand what I need to do.

I've known Ruby for a long time and a little of Java. This project needs to be JRuby because of old Java code that needs to be integrated with new Ruby code.

1 Answer 1

3

For a complete reference, see the Calling Java From JRuby wiki page, specifically the section about closure conversion. The short answer to your question is that your Java method count_all_disk_files will need to accept an interface with a single method (a "functional interface"). Then JRuby will be able to automatically implement that interface with the code from the block.

Sign up to request clarification or add additional context in comments.

1 Comment

this helped me a lot, even more then the official docs. thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.