0
votes

I'm trying to implement this protected constructor from this abstract Java class into my clojure project. If I write:

(org.everit.json.schema.Schema.) 

then I get an error that says:

CompilerException java.lang.IllegalArgumentException: No matching ctor found
for class org.everit.json.schema.Schema.

I clearly see the constructor, but I see that it is protected. I've been reading up on proxy, and gen-class, but I can not understand how to extend this abstract class to my project so that I can use the constructor without having to override it.

From my research, it seems like I do have to overwrite it. Can someone help me out with whether I do have to or not? Thanks.

I see that Schema is extended to ObjectSchema and StringSchema for implementations, so I've imported those as well, but I'm getting errors that say "No matching field found" when trying to use against a string schema or a JSONObject schema.

2

2 Answers

1
votes

(org.everit.json.schema.Schema.) invokes a constructor that accepts no arguments, i.e.:

class Schema {
  protected Schema() {
    ...
  }
}

According to Java Language Specification, if a class declares at least one constructor, a default no-arg constructor won't be generated by a compiler. As Schema class defines that one constructor thus no no-arg constructor will be generated by the compiler and the only constructor available in this class is Schema(Builder<?> builder).

This shows how you can create dummy instances of a Schema.Builder and Schema using proxy in REPL:

(import 'org.everit.json.schema.Schema)
(import 'org.everit.json.schema.Schema$Builder)

(defn dummy-schema-builder []
  (proxy [Schema$Builder] []))

(defn dummy-schema [builder]
  (proxy [Schema] [builder]
    (accept [visitor]
      (println "Processing" visitor))))

(dummy-schema
  (dummy-schema-builder))
0
votes

Look at this answer: Make a class that extends a class with overriding in clojure

You could also create a Java subclass and then use interop from Clojure to access it.

Here is another answer: How to call super class when extending a Java class using genclass in Clojure?