title: Extending (not implementing) Java interfaces in Clojure
body: <p>I've been looking a lot at Clojure recently and I've been wondering if it suits the scope of my next project.  Unfortunately, it involves writing non-portable code and I need access to the Win32 API.</p>
  
  <p>I stumbled upon  the <a href="http://jna.java.net/" rel="nofollow">Java Native Access</a> library for easily mapping native libraries with a C interface into Java.  It even provides an (empty) wrapper for <code>Kernel32.dll</code> as an example in the tutorial!</p>
  
  <p>However, I'm a bit stumped as to translating the examples from Java to Clojure.  I know I can <a href="http://clojure.org/java_interop" rel="nofollow">implement interfaces and implement classes</a>, but how can I simply <em>extend an interface</em>?</p>
  
  <hr>
  
  <p>Thanks to the link posted by Joost, here is a minimal working example:</p>
  
  <pre><code>(import (com.sun.jna Library Native Platform Pointer))
  (import (com.sun.jna.win32 StdCallLibrary))
  
  (def K32
       (gen-interface
        :name Kernel32
        :extends [com.sun.jna.win32.StdCallLibrary]
        :methods [[GetCurrentProcess [] com.sun.jna.Pointer]]))
  
  (defn load-native-library [name interface]
    (cast interface (com.sun.jna.Native/loadLibrary name interface)))
  
  (def k32 (load-native-library "kernel32" K32))
  
  (println (.GetCurrentProcess k32))
  </code></pre>
  
  <p>Outputs <code>#&lt;Pointer native@0xffffffff&gt;</code>, as expected!</p>