title: How to cast explicitly in clojure when interfacing with java
body: <p>In trying to use weka from clojure, I'm trying to convert <a href="http://weka.wikispaces.com/Programmatic+Use" rel="nofollow">this howto guide</a> from the weka wiki to clojure using the java interop features of clojure.</p>
  
  <p>This has worked well so far, except in one case, where the clojure reflection mechanism can't seem to find the right method to invoke - I have:</p>
  
  <pre><code>(def c-model (doto (NaiveBayes.) (.buildClassifier is-training-set)))
  </code></pre>
  
  <p>Later this will be invoked by the <code>.evaluateModel</code> method of the <code>Evaluation</code> class:</p>
  
  <pre><code>(.evaluateModel e-test c-model is-testing-set)
  </code></pre>
  
  <p>where <code>e-test</code> is of type <code>weka.classifiers.Evaluation</code> and, according to <a href="http://weka.sourceforge.net/doc.dev/weka/classifiers/Evaluation.html#evaluateModel%28weka.classifiers.Classifier,%20weka.core.Instances,%20java.lang.Object...%29" rel="nofollow">their api documentation</a> the method takes two parameters of types <code>Classifier</code> and <code>Instances</code></p>
  
  <p>What I get from clojure though is <code>IllegalArgumentException No matching method found: evaluateModel for class weka.classifiers.Evaluation  clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:53)</code> - I guess that this is because <code>c-model</code> is actually of type <code>NaiveBayes</code>, although it should also be a <code>Classifier</code> - which it is, according to <code>instance?</code>.</p>
  
  <p>I tried casting with <code>cast</code> to no avail, and from what I understand this is more of a type assertion (and passes without problems, of course) than a real cast in clojure. Is there another way of explicitly telling clojure which types to cast to in java interop method calls? (Note that the original guide I linked above also uses an explicit cast from <code>NaiveBayes</code> to <code>Classifier</code>)</p>
  
  <p>Full code here: /http://paste.lisp.org/display/129250</p>