在 Clojure 中使用 gen-class 声明成员变量 [英] Declare Member Variables with gen-class in Clojure

查看:15
本文介绍了在 Clojure 中使用 gen-class 声明成员变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习如何在 Clojure 中扩展 Java 类,但我没有看到声明新成员变量的方法;我只看到方法的方法.

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
  (:gen-class
    :methods [[foo [] String]]))

是否有 :members 关键字或其他声明成员变量的方式?

Is there a :members keyword or another way of declaring member variables?

推荐答案

:状态名称

如果提供,将创建具有给定名称的公共最终实例字段.您必须提供 :init 函数才能为状态提供值.请注意,虽然是最终状态,但状态可以是引用或代理,支持创建具有事务或异步突变语义的 Java 对象.

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.

这篇关于在 Clojure 中使用 gen-class 声明成员变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆