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.

WorldsEndless
  • 1,493
  • 1
  • 15
  • 27
  • 3
    Add some code to better understanding .. – Janny Sep 16 '14 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 ]]]. I need to pass the top-level one to Clojure and be able to get at the lower levels as needed. – WorldsEndless Sep 16 '14 at 11:28
  • Calling clojure from java http://stackoverflow.com/questions/2181774/calling-clojure-from-java?rq=1 – edbond Sep 16 '14 at 11:48
  • @edbond I've gone through that one; the major difference here is that I'm not passing primitives to Clojure; I'm passing a layered object, and I'm not sure how to do that or deal with it. – WorldsEndless Sep 16 '14 at 11:57
  • 2
    I don't see the difference. You can import RP and call (.. rp .getRF .getRO .getRA .getName) – edbond Sep 16 '14 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 `..`. – amalloy Sep 17 '14 at 01:21

1 Answers1

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.

amalloy
  • 89,153
  • 8
  • 140
  • 205