clojureclojureclr

Call non-virtual protected methods from a Java/C# subclass in Clojure/ClojureCLR


When making a subclass in Clojure using gen-class, you can expose protected virtual(non-final) methods through exposes-methods, however it is implemented through overriding, which cannot work for non-virtual(final) methods.

Is the only way to call a protected method this way through reflection?

Can reify or proxy do this better than gen-class?


Solution

  • This turned out to be a bug in clojure-clr. It probably works fine in the JVM version. Clojure does allow calling non-virtual/final methods if they're protected/public. However, the method I was trying to call was protected internal, which actually means protected or internal. clojure-clr was incorrectly interpreting this as protected and internal, internal meaning only accessible within the same assembly. Due to this, my method call was failing.

    This has been fixed in the latest version of clojure-clr.