You can just define a variable with def in the file containing gen-class. gen-class won't help with this; it's just regular Clojure functionality:
(def CLASSNAME "MyClass") That variable will be specific to the generated class, and public at least in the sense that it can be accessed in Clojure from outside the namespace. However, I'm not certain whether a Java class will be willing to access it by MyClass.CLASSNAME, if that's what you need. You can try it and see whether it works. I've used gen-class a but, I've never had to define a static field for use by Java classes. You can certainly define static methods, so if it would work to simply let Java get the value of CLASSNAME using an accessor method, you can do that using :methods in gen-class. I haven't done this, but the gen-class docstring gives a tip about how to do it. you'll then have to define a function to implement the accessor outside of gen-class, named e.g. "-getCLASSNAME" for an accessor that Java will see as "getCLASSNAME". (You probably know that already.) On Sunday, April 16, 2017 at 1:43:17 AM UTC-5, lambda-knight wrote: > > Hi, > > I am re-writing a Java class in Clojure using gen-class which is > accessible from Java. > The class has a static field. Let's assume a Java class as follow: > > public class MyClass { > public static final String CLASSNAME = "MyClass"; > private String name; > private int value; > > public MyClass() {} > > public String getName() { > return this.name; > } > public void setName(final String name) { > this.name = name; > } > public int getValue() { > return this.value; > } > public void setValue(final int value) { > this.value = value; > } > } > > Can I define a such field in Clojure ? > > Thanks, > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.