How do I implement a Java interface in Clojure

后端 未结 5 748
隐瞒了意图╮
隐瞒了意图╮ 2020-12-05 14:53

How do I create a Clojure object that implements this interface and then gets called from Java code?

public interface Doer {
   public String doSomethin(Stri         


        
5条回答
  •  余生分开走
    2020-12-05 15:15

    If doSomethin() is defined in your interface, you should not mention it in :methods. Quote from http://clojuredocs.org/clojure_core/clojure.core/gen-class:

    :methods [ [name [param-types] return-type], ...]
    The generated class automatically defines all of the non-private
    methods of its superclasses/interfaces. This parameter can be used
    to specify the signatures of additional methods of the generated
    class. Static methods can be specified with ^{:static true} in the
    signature's metadata. Do not repeat superclass/interface signatures
    here.
    

提交回复
热议问题