0

I have a .java file that will be called for its public String solve() method to answer a problem. The method receives project-defined Java class RP, which contains a collection of RF, which each contain a collection of RO, which each contain several RA which, finally, boil down to String, String pairs (a name and a value). My question is, (how) can I have that solve() method pass its RP object to Clojure where I believe I can do all the work to generate a solution more effectively, and eventually return a String solution back?

EDIT: What I'm looking for is some way of saying, String answer = toClojure(RP); and in Clojure I'll be able to do the equivalent of RP.getRF().getRO().getRA().getName(), where each of these functions is defined in the Java classes.

6
  • 3
    Add some code to better understanding .. Commented Sep 16, 2014 at 10:07
  • @Jani we're talking about nested data structures here, so I'm not sure what code to give. There are four classes here which, along with some functions, basically boil down to: Collection[Collection[Collection[Collection <String, String>]]]. I need to pass the top-level one to Clojure and be able to get at the lower levels as needed. Commented Sep 16, 2014 at 11:28
  • Calling clojure from java stackoverflow.com/questions/2181774/… Commented Sep 16, 2014 at 11:48
  • 2
    I don't see the difference. You can import RP and call (.. rp .getRF .getRO .getRA .getName) Commented Sep 16, 2014 at 12:27
  • 1
    @edbond You want (-> rp .getRF .getRO .getRA .getName), or (.. rp getRF getRO getRA getName) if you insist on using ..: the . interop is added automatically by ... Commented Sep 17, 2014 at 1:21

1 Answer 1

2

Just pass it the object reference, same as you would pass it to a java method. Clojure doesn't need any special magic to receive java objects.

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

Comments

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.