Declare Member Variables with gen-class in Clojure

前端 未结 3 604
盖世英雄少女心
盖世英雄少女心 2021-01-13 20:49

I\'m learning how to extend Java classes in Clojure, but I don\'t see a way declare new member variables; I only see a way for methods.

(ns test.aclass
  (:g         


        
3条回答
  •  猫巷女王i
    2021-01-13 21:17

    :state name

    If supplied, a public final instance field with the given name will be created. You must supply an :init function in order to provide a value for the state. Note that, though final, the state can be a ref or agent, supporting the creation of Java objects with transactional or asynchronous mutation semantics.

    There is an example on the website of how it can be used.

提交回复
热议问题