0

My question is related to closure conversion. I want to test a proc that implements a functional interface from jruby code.

I have a simple proc like

proc { print 'hey!' }

to implement a java functional interface like

public void doStuff()

Since the client object is a Java object that is

public class MyClient {
    private MyInterface iface;

    public MyClient(MyInterface iface) {
        this.iface = iface;
    }

    public void doHighLevelStuff() {
        this.iface.doStuff();
    }
}

it works right, since jruby manages to "cast" the proc into a java functional interface. So, this part it's ok.

My problem is testing this code, calling it from jruby. I don't know how to tell jruby to treat that proc as an implementation of MyInterface to be able to call the actual method doStuff instead of the ruby specification call.

So, the question is how to tell jruby to treat a proc as a given java interface.

1 Answer 1

0

client = MyClient.new { print 'hey! } and then client.doHighLevelStuff should work just fine ... if you have a proc instance simply pass it in (&proc) as a block into the constructor.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.