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:
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)
?
I think the flow chart is wrong. Checking the Clojure - Datatypes: deftype, defrecord and reify documentation we can see that:
- a deftype/defrecord can implement one or more protocols and/or interfaces
There is no mention of extending an existing class. Indeed, looking at the documentation for defrecord
itself there is no mention of extending existing classes, except for Object
as a special case.
Sorry, it looks like either proxy
or gen-class
are your only options.