From my research, the way to extend a Java class is basically with either gen-class in a namespace or with proxy. But looking at the Clojure type selection flowchart, it seems to suggest that I can use record to extend a Java class:
- Will the type need to extend a Java class or implement any interfaces? Yes
- Do you need a named type or only an instance of an anonymous type? Named type
- Do you need to be able to refer to the class statically from Java? No
- Is your class modelling a domain value - thus benefiting from hasmap-like functionality and sematics? Yes
Use defrecord
So the question is... how?
For example (from this):
public final class Second extends Struct {
public final Signed32 a_number = new Signed32();
public Second(final Runtime runtime) {
super(runtime);
}
}
public final class Top extends Struct {
public final Second second = inner(new Second(getRuntime()));
public final Second[] seconds = array(new Second[5]);
public final Signed32 another_number = new Signed32();
public final Signed32[] more_numbers = array(new Signed32[5]);
public Top(final Runtime runtime) {
super(runtime);
}
}
Do I...
(defrecord Second)
(extend jnr.ffi.Struct
Second)
?